Defaulting a "Medium Time" field to be "p.m." instead of "a.m."?

Cobo

Registered User.
Local time
Today, 02:33
Joined
Mar 3, 2010
Messages
17
Defaulting a "Medium Time" field to be "p.m." instead of "a.m."?

Hello all,

I assume this must be a pretty basic question but after a while searching I haven't found a solution.

I have a Date/Time field in my database with a "medium time" format. The problem that I have is that if you don't specify if the hour is in AM or PM it defaults it to AM. I'd like to have the opposite behaviour.. that when I write "5.30" it stores it as "5.30 pm" except if I explicitly input "5.30 am".

Thanks a lot for helping.

Cheers!
 
Re: Defaulting a "Medium Time" field to be "p.m." instead of "a.m."?

If you input the time in 24 hour format ie. 17:30 it will display as 5:30 PM.

I'm not sure that there is any way to force an input of 5:30 to default as 5:30 PM. It is my guess that any time you input will be stored in 24 hour format, regardless of how the field is formatted for display purposes, so unless you explicitly state 5:30 PM or 17:30 the system will always return an input of 5:30 as 05:30 or 5:30 AM
 
Re: Defaulting a "Medium Time" field to be "p.m." instead of "a.m."?

If you input the time in 24 hour format ie. 17:30 it will display as 5:30 PM.

I'm not sure that there is any way to force an input of 5:30 to default as 5:30 PM. It is my guess that any time you input will be stored in 24 hour format, regardless of how the field is formatted for display purposes, so unless you explicitly state 5:30 PM or 17:30 the system will always return an input of 5:30 as 05:30 or 5:30 AM
Oh, that's sad... but what can you do!

Thanks for the reply. Cheers!
 
Re: Defaulting a "Medium Time" field to be "p.m." instead of "a.m."?

the times are 24 hour clock times

so 0530 IS 5:30 AM

you either need to enter

1730 to get 5:30PM
or actually enter 5:30 PM

--------
however one problem with entering times is that the format for an acceptable time entry is not obvious - and you cant have a timepicker, in the same way you have a date picker.

perhaps have a am/pm check box, and manipulate the time with a bit of code.
 
Re: Defaulting a "Medium Time" field to be "p.m." instead of "a.m."?

Put the following in a standard module:
Code:
Public Function checkTime(strInput As String) As Date
Dim intHour As Integer
If InStr(1, strInput, "AM") > 0 Then
    checkTime = Format(CDate(strInput), "hh:mm")
Else
    intHour = CInt(Mid(strInput, 1, InStr(1, strInput, ":") - 1))
    intHour = IIf(intHour < 12, intHour + 12, intHour)
    strInput = CStr(intHour) & Mid(strInput, InStr(1, strInput, ":"))
    checkTime = Format(CDate(strInput), "hh:mm")
End If
End Function

and in the onChange event of your field, set the value of the field = checkTime(field.Text) If you enter "5:30 AM" it will return 05:30:00 AM. If you enter "5:30" or "5:30 PM" it will return 05:30:00 PM
 

Users who are viewing this thread

Back
Top Bottom