Forum Moderators: open

Message Too Old, No Replies

How to format time without the seconds in ASP

         

kevinj

8:52 pm on May 12, 2005 (gmt 0)

10+ Year Member



I have a form that displays the time entered into a database. If the time is entered as 12:30 PM in the database, when I display it on the form it shows 12:30:00 PM. How can I get it to drop the seconds in the display on the form? Left and Right trimming won't really work if someone enters a time like 1:00 PM

Thanks!

john_k

9:04 pm on May 12, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Function NormalTimeString(dat)
Dim lHour
Dim sSuffix
If IsDate(dat) Then
lHour = Hour(dat)
If lHour > 12 Then
lHour = lHour - 12
sSuffix = " PM"
ElseIf lHour = 12 Then
sSuffix = " PM"
ElseIf lHour = 0 Then
lHour = 12
sSuffix = " AM"
Else
sSuffix = " AM"
End If
NormalTimeString = CStr(lHour) & ":" & Right("00" & CStr(Minute(dat)), 2) & sSuffix
Else
NormalTimeString = ""
End If
End Function

Function NormalDateString(dat)
If IsDate(dat) Then
NormalDateString = CStr(Month(dat)) & "/" & CStr(Day(dat)) & "/" & _
CStr(Year(dat))
Else
NormalDateString = ""
End If
End Function

mrMister

9:34 pm on May 12, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



FormatDateTime might also do the trick. It depends how you want your time formatting.

FormatDateTime(yourTime,vbShortTime)

john_k

12:23 pm on May 15, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



vbShortTime returns the time in a 24 hour /military time format. It doesn't bring back the AM/PM indicator.

vbLongTime returns the AM/PM indicator, but it also brings back the milliseconds.

Their isn't a named format to return the time in the format that most people in the U.S. are accustomed to seeing. (that is why the function I posted was named NormalTimeString :)