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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

24 Hour Time with Seconds

Status
Not open for further replies.

DonP

IS-IT--Management
Jul 20, 2000
684
US
I need to get the current time in 24 hour format but I need the seconds too and I don't want the date. Right now, with:

[tt]FormatDateTime(now(),vbshorttime)[/tt]

it gives only the hour and minute. How can I add the seconds? Don
don@pc-homepage.com
Experienced in HTML, Perl, VBScript, PWS, IIS and Apache. Run OS/2 Warp 4, BeOS v5 and Windows NT/2000 (only when I have to!)
 
Looks like you'll just need to format it yourself, so:

dim theTime
theTime = FormatDateTime(now(),VBLongTime)

'check if time is PM and add 12 hours if so
if right(cstr(theTime),2) = "PM" then
theTime = DateAdd("H",12,theTime)
end if

'chop off the AM/PM
theTime = left(cstr(theTime),len(theTime)-2)

:)
paul
penny1.gif
penny1.gif
 
Thanks Paul,

It seems to be what I'm after except that it gives odd results:

[tt]12/31/1899 1:02:31[/tt]

I need the time only and in 24 hour format. What I tried to do originally was to get only the seconds and concatonate them to the string I had but I wasn't sure of the format to get only the seconds. Don
don@pc-homepage.com
Experienced in HTML, Perl, VBScript, PWS, IIS and Apache. Run OS/2 Warp 4, BeOS v5 and Windows NT/2000 (only when I have to!)
 
If you only want to pull part of a date or time use the DatePart() function.
dim secs
secs = datePart("S",Date())

I am not sure about that first parameter though. But you can look it up on quickly enough.

Roj
 
Thanks,

This is very close now to what I want except that the seconds are wrong:

[tt]14:18:0[/tt]

I must have a typo but I can't find it. Here is what I have:

time24 = FormatDateTime(now(),vbshorttime)

dim secs
secs = datePart("S",Date())
theTime = time24 & ":" & secs Don
don@pc-homepage.com
Experienced in HTML, Perl, VBScript, PWS, IIS and Apache. Run OS/2 Warp 4, BeOS v5 and Windows NT/2000 (only when I have to!)
 
Ok, I figured it out and here it is in case someone else needs it:

[tt]time24 = FormatDateTime(now(),vbshorttime)

secs = Second(now())
theTime = time24 & ":" & secs[/tt]

It gives only the hour:minute:second in 24 hour format Don
don@pc-homepage.com
Experienced in HTML, Perl, VBScript, PWS, IIS and Apache. Run OS/2 Warp 4, BeOS v5 and Windows NT/2000 (only when I have to!)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top