Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to reterieve the AM or PM part of a time when using Now function.

Status
Not open for further replies.

hallian92

Programmer
Jul 30, 2002
8
US
Hi,

Does anyone know how to reterieve the AM or PM part of a time when you get the current PC time. I know the following gets the day,month,year,hour,minute and second but how can I also reterieve the AM or PM part also. Any help is appreciated

MyDateTime = Now 'get the current system date/time
day(MyDateTime)
month(MyDateTime)
year(MyDateTime)
hour(MyDateTime)
minute(MyDateTime)
second(MyDateTime)

Thanks
 
This should work:

Debug.Print Right$(Now, 2) Swi
 
I don't know of any function to determine AM/PM, but this should work:

if hour(now())>=12 then
msgbox "PM"
else
msgbox "AM"
 
Hi,

Swi's solution is best while DangerPowers' solution won't work with a 24 hour clock. I am not sure if there are variations of meridiem in the rest of the world?

Have a good one!
BK
 
The hour() function returns an integer between 0 and 23 regardless of the type of clock used.

The now() function returns the date-time depending on the way Windows Regional settings are used.

I actually have a 24 hour clock and right$(now,2) returns the seconds.
 
I typed this in the immediate window and got just what you want. It works with any international setting.

?right(format(now,"h:m:s AM/PM"),2)
Let me know if this helps

Check out FAQ222-2244
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top