Saturday, December 12, 2009

Excel VBA Example: Date Calculations

To add or subtract an interval (a relative date) from a date, we could use DateAdd function. The syntax is:

DateAdd(interval, number, date)
The DateAdd function syntax has these named arguments:
Part Description
interval Required. String expression that is the interval of time you want to add.
number Required. Numeric expression that is the number of intervals you want to add. It can be positive (to get dates in the future) or negative (to get dates in the past).
date Required. Variant (Date) or literal representing date to which the interval is added.

The interval argument has these settings:
Setting Description
yyyy Year
q Quarter
m Month
y Day of year
d Day
w Weekday
ww Week
h Hour
n Minute
s Second

The following example add two months to October 31, 2009:

MsgBox DateAdd("m",2,"31-Jan-09"))


Thank you for reading this article Excel VBA Example: Date Calculations With URL http://x-tutorials.blogspot.com/2009/12/excel-vba-example-date-calculations.html. Also a time to read the other articles.


Write your comment for this article Excel VBA Example: Date Calculations above!