
Tips.Net > WordTips Home > Macros > Calculating a Future Date
Summary: VBA provides the DateAdd function to perform math on dates. This tip describes how to add and subtract dates to calculate future and past dates. (This tip works with Microsoft Word 97, Word 2000, Word 2002, and Word 2003.)
If you are creating a VBA macro to do some processing on a document, you may have a need to calculate a date at some point in the future. Using the VBA DateAdd function, this is quite easy. The function has the following syntax:
DateAdd(interval, number, startdate)
The original date that you begin with (typically today's date) is specified by the startdate argument. The interval argument indicates what you want to add to the startdate. For instance, if you want to add days, then interval would be the letter d. There are many different intervals you can specify:
| Interval | Meaning | |
|---|---|---|
| d | Day | |
| ww | Week | |
| m | Month | |
| q | Quarter | |
| yyyy | Year | |
| y | Day of year | |
| w | Weekday | |
| h | Hour | |
| n | Minute | |
| s | Second |
Finally, the number argument specifies how many intervals you want to add to the date.
As an example, let's suppose you wanted to know the date that was 90 days in the future. You could use the following:
dFutureDate = DateAdd("d", 90, Date)
When executed, dFutureDate contains the date that is 90 days after today.
Tip #1476 applies to Microsoft Word versions: 97 2000 2002 2003
Great Idea! Uncover the many ways you can master the full potential of printing your documents. WordTips: Printing and Printers can help you get the most from both the printed page and your printer.
The real power behind Word's best documents lies in understanding styles and templates. Learn the key to more powerful document creation. (more information...)
Ask a Word Question
Make a Comment
Beauty Tips
Bugs and Pests Tips
Car Tips
Cleaning Tips
College Tips
Cooking Tips
Excel2007 Tips
ExcelTips
Family Tips
Gardening Tips
Health Tips
Home Tips
Money Tips
Organizing Tips
Pet Tips
Word2007 Tips
WordTips