formatting time question.

1. Senior Member
Join Date
Dec 1969
Posts
252

## formatting time question.

Hi,<BR><BR>in the database i have fields as short time and i want to format it in a way so user can change the time if they want. And so i want to format it like this : 6:07.<BR><BR>It is displaying in my forms in the format of this : 6:06:00 PM<BR><BR>How can i fix that. Thanks.

2. Senior Member
Join Date
Dec 1969
Posts
252

## in addition.. if i use the

FormatDateTime(value,4) it formats it to ##:## to how i want it but its in millitary time. And so i dont know how to make it to convert to millitary time based on AM or PM. thanks.

3. Senior Member
Join Date
Dec 1969
Posts
96,118

## Have to do it by hand...

&#060;%<BR>Function FormatTime( tm )<BR> Dim hr, ampm<BR> If Not isDate(tm) Then <BR> FormatTime = "?:?? ??"<BR> Else<BR> tm = CDate(tm)<BR> hr = Hour(tm)<BR> If hr &#062;= 12 Then ampm = " PM" Else ampm = " AM"<BR> If hr &#062; 12 Then hr = hr - 12<BR> If hr = 0 Then hr = 12<BR> FormatTime = hr & ":" & Right("0" & Minute(tm),2) & ampm<BR> End If<BR>End Function<BR>%&#062;<BR><BR>

4. Senior Member
Join Date
Dec 1969
Posts
11,247

## Ahh Second Hand code

Take a minute to think over that one

5. Senior Member
Join Date
Dec 1969
Posts
96,118

## Hmmm...want a Second way?

Function FormatTime( tm )<BR> Dim re<BR> tm = CDate(tm)<BR> Set re = NewRegexp<BR> re.Pattern = ":dds"<BR> FormatTime = re.Replace( FormatDateTime(tm,vbLongTime), " " )<BR>End Function<BR>

6. Senior Member
Join Date
Dec 1969
Posts
11,247

## RE: Hmmm...want a Second way?

Too much time on your hands!<BR><BR>Over-clocked?

#### Posting Permissions

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