Link to home
Start Free TrialLog in
Avatar of rinkydink
rinkydink

asked on

Excel vba question

Hi, my excel code returns the time in military time - my OS is not set to military time, how can I take the time function out of returning military time?

I am using Excel 2010


Thanks much,



Dim x As Date

x = Format(Date, "mm-dd-yyyy")


Selection = x & "---" & Time

Avatar of Dave
Dave
Flag of Australia image

You can force AM:PM as below

Regards

dave
Dim x As Date

Selection = Format(Date, "mm-dd-yyyy") & "--" & Format(Time, "hh:mm:ss AMPM")

Open in new window

Avatar of rinkydink
rinkydink

ASKER

Yes, I tried using Format(Time, "hh:mm:ss ampm") but it still returns the time in military time format.

I have the same OS Regional settings on my pc at home and Selection=Time returns the time in hh:mm:ss AMPM but I run Office 2007 at home and 2010 at work but I can find no setting in 2010 that appears to be forcing military time.

ASKER CERTIFIED SOLUTION
Avatar of Rowan Scott
Rowan Scott
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Oh i should have mentioned,
Macro1 and Macro2 are the same except for using Dateserial and Timeserial
I just wanted to point out the value of those functions because it makes it easy to leave out the seconds if you don't actually want them. It also makes it easy to get dates such as last date of previous month, Last quarter, and things like that.

Best Regards