PDA

View Full Version : Using DateAdd() For Modifying Time and Dates


admin
05-30-2003, 01:20 PM
There's a built-in function named DateAdd() that can be quite useful. For example, if you wanted a cookie to expire at a certain time or date you could use this function.

Below we display the current date/time and then we add one hour to the time. Here's the code:

Response.Write "Now = " & Now
Response.Write "<br>"
Response.Write "Now + 1 = " & DateAdd("h", 1, now)

If you want to adjust the month then replace the h with a m. You can also give negative numbers:

Response.Write "Now = " & Now
Response.Write "<br>"
Response.Write "Now - 1 = " & DateAdd("m", -1, now)

The result decreases the month by one.