How to compare times - only need AM/PM

G

gweasel

I've got a logbook set up which has users enter a Due Date and Due
Time (AM/PM - not exact time). When record is edited, I want to check
that that due date is not earlier than the current date. That, I've
got working (using the built in Date() function). I need to do
something similar with the time - but when I do Time() it pulls in the
full time. How can I have it check the system time but only display/
hold onto the AM/PM value?
 
K

kingston via AccessMonster.com

To return the system AM/PM value, you can use:

Right(Time(),2)
 
A

Arvin Meyer [MVP]

You'll need a custom function like this one:

Public Function AMPM(dtmIn As Date) As String
If DatePart("h", dtmIn) > 11 Then
AMPM = "PM"
Else
AMPM = "AM"
End If
End Function

Use it like this in the immediate window:

? AMPM(Now)
AM

or in a query:

Select MyDateField AMPM([MyDateField]) From MyTable;

It is important that the date that's fed to the function contains the time,
even if it is formated to display only the date. If you use Date() instead
of Now() to collect the date the time will always be AM since Date() is
always the time at 12:00:00 AM. To display the date only using Now() use:

Format(Now(), "Short Date")
 
Top