Add a time interval to a Date
Syntax
DateAdd (interval,number,date)
Key
number The number of intervals to add
date The date
interval The date/Time interval to add:
yyyy Year
q Quarter
m Month
y Day of year
d Day
w Weekday
h Hour
n Minute
s Second
To subtract dates just specify number as a negative, i.e. "m", -6 will subtract 6 months.
Add 7 days:
dtmStart="18-Feb-10"
WScript.Echo "Start Date" & dtmStart
dtmFinish=DateAdd("d",7,dtmStart)
WScript.Echo "End Date" & dtmFinish
PowerShell equivalent:
$demo = (get-date).AddDays(7)
also
(get-date).AddHours(12)
(get-date).AddMilliseconds(64)
(get-date).AddMinutes(64)
(get-date).AddMonths(64)
(get-date).AddSeconds(25)
(get-date).AddTicks(100)
(get-date).AddYears(99)$demo = ((get-date).AddHours(2)).AddMinutes(45)
“We waste time looking for the perfect lover, instead of creating the perfect love” ~ Tom Robbins
Date - The current system date.
DateDiff - Return the time interval between two dates.
DatePart - Return a unit of time from a date.
DateSerial - Return a Date from a numeric Year, Month and Day.
Weekday - Return the day of the week.
Q218964 - VBScript Date and Time formats change with logged on user.
Equivalent PowerShell: Date.AddDays(-7)