Forum Moderators: open

Message Too Old, No Replies

adding hours to the time and date

         

lindajames

2:05 pm on Feb 18, 2004 (gmt 0)

10+ Year Member



hi,

i need to add 5 hours to the current server time&date, can anyone please tell me how i can do this? lets say the current date and time on the server is 18 Feb 2004 23:20 and 5 hours added to that will make the date&time 19 Feb 2004 04:20

any help would be very much appreciated.

cheers
linda

lindajames

3:26 pm on Feb 18, 2004 (gmt 0)

10+ Year Member



doesnt matter, i've figured it out:

dtNow = Now()
Response.Write DateAdd("h", 5, dtNow)

Xoc

9:07 pm on Feb 18, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The VBA data format is simply the number of days since December 30th, 1899 at midnight expressed as a floating point number. The hours are expressed as a fraction of a day.

Hence, if you take a date and add 14 to it, you will get two weeks later.

If you add 5/24 (0.20833) to it, you will get 5 hours later.

So if you simply did:


Call Response.Write(CDate(Now + 5/24))

That will accomplish the same task. The CDate will make sure that the response gets converted back into a date instead of being treated as a floating point number.