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!

Date and military (short) time format?

Status
Not open for further replies.

shart00

Technical User
Jun 16, 2003
63
US
Hi,
I'm struggling with getting this format to work withing VB. Can you help?

Here's a snip of the code which displays current date and time, username, and a comments section.

InsertNote = Now & ": " & Environ$("username") & " - " & mymemo & vbCrLf

The code above makes the date and time look like 06/18/03 1:30:55 PM. I would prefer to see 6/18/03 13:30. Any help would be appreciated.

Thanks, Shawn
 
format(Now,"mm/dd/yy hh:mm:ss")

Mike Pastore

Hats off to (Roy) Harper
 
Shawn,

The Now() function returns the date/time as per the control panel, which uses international settings.

Try using instead:

InsertNote = Format(Now(),"m/dd/yy hh:mm:ss") & ": " & Environ$("username") & " - " & mymemo & vbCrLf

I should point out that the Environ function with username is only implemented out of the box on Windows NT/2000/XP so this code will fail if run on Win9x systems (and possibly WinME as well, have not tested).
There are a number of threads around that detail how to obtain the Windows network username via API calls which are more reliable if you use the older systems.

John
 
Try:

InsertNote =format(now,"mm/dd/yyyy hh:nn") & ": " & Environ$("username") & " - " & mymemo & vbCrLf

to get 06/18/2003 15:54

of use format(now,"m/d/yy hh:nn") to get 6/18/03 15:55



 
Great!!! It worked. I was close but my syntax was off. Thanks all.

Shawn
 
Another way to do this for year format ->

nts = Format(nts, "mm/dd/yyyy hh:mm:ss")

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top