| Answer: |
VBScript provides a handy function for adding or subtracting various intervals to a date variable. This function, DateAdd has the following definition:
DateAdd(interval, number, date)
|
The interval specifies the date part that you wish to add or subtract from the date. interval can have the following values:
yyyy - Year
q - Quarter
m - Month
y - Day of year
d - Day
w - Weekday
ww - Week of year
h - Hour
n - Minute
s - Second
Observe the following script to see how to use DateAdd with various intervals:
'Get the current date/time Dim dtNow dtNow = Now()
'Will display the date/time 24 hours from now Response.Write DateAdd("h", 24, dtNow)
'Will display the date/time 12 hours PRIOR from the current time Response.Write DateAdd("h", -12, dtNow)
'Will display the date/time 1 week from now Response.Write DateAdd("ww", 1, dtNow)
'Will display the date/time two months ago Response.Write DateAdd("m", -2, dtNow)
|
Note that to subtract time, you simply specify a negative number.
For more information on DateAdd be sure to read the technical docs and this 4Guys article: Using VBScript's Date Functions.
Happy Programming!
|