If minutes less than 10 in DatePart?

# Thread: If minutes less than 10 in DatePart?

1. Member
Join Date
Dec 1969
Posts
70

## If minutes less than 10 in DatePart?

Hi!<BR>Here is my function which takes only the hour and minutes out of a SQL datetime variable. <BR>Function GetTime(strDT)<BR> GetTime = DatePart("h", strDT) & ":" & DatePart("n", strDT)<BR>end if<BR>The problem I am having is the minutes - when it is less than 10 minutes, (i.e., 07), it only prints the 7. So the actual time looks like 6:7 on the report. Any ideas on how to get this to print a 07 (i.e., 6:07) for the report?<BR>Thanks in advance,<BR>-L<BR>

2. kannys ( the guru) Guest

## oh yes

Yes make an IF statement such that if minutes is &#060; 10 THEN "0" + minutes...<BR><BR>comprendre???<BR>do something along those lines

3. Member
Join Date
Dec 1969
Posts
70

## If minutes less than 10 in DatePart

Okay, tried this, and now I am getting <BR>"Microsoft VBScript runtime error &#039;800a01f5&#039; <BR><BR>Illegal assignment: &#039;DatePart&#039; "<BR>Here is what I have tried to do:<BR> Function GetTime(strDT)<BR> GetTime = DatePart("h", strDT) & ":" & DatePart("n", strDT)<BR> if DatePart("n", strDT) &#060; 10 then<BR> DatePart = "0 + DatePart(&#039;n&#039;, strDT)"<BR> end if<BR> End Function<BR><BR>Any ideas on how this should be coded so that it works?<BR>Thx!<BR><BR>

4. Senior Member
Join Date
Dec 1969
Posts
109

## replace

replace<BR><BR>DatePart = "0 + DatePart(&#039;n&#039;, strDT)"<BR><BR>with<BR><BR>DatePart = "0" + DatePart(&#039;n&#039;,strDT)

5. Member
Join Date
Dec 1969
Posts
70

## RE: replace - thanks but still not working

Thanks, but this still receives the same error.<BR>Any more ideas?<BR>Thx!<BR>-L

6. Senior Member
Join Date
Dec 1969
Posts
402

## do it like this....

wehat you need to do is add 100 to the minutes and then take the right 2 chars after converting this to a string:<BR><BR>GetTime = DatePart("h", strDT) & ":" & Right(CStr(100 + DatePart("n", strDT)), 2)<BR><BR>hope this helps. jb

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•