Please Note: This article is written for users of the following Microsoft Word versions: 2007, 2010, 2013, and 2016. If you are using an earlier version (Word 2003 or earlier), this tip may not work for you. For a version of this tip written specifically for earlier versions of Word, click here: Determining Differences Between Dates.
Written by Allen Wyatt (last updated June 18, 2018)
This tip applies to Word 2007, 2010, 2013, and 2016
When you are programming macros, you should know that dates are stored internally, within variables, as serial numbers. The serial number represents the number of days elapsed since a starting "base date," specifically since 1 January 100. (Yes, that's the year 100.) This means that you can perform math with the serial numbers, if desired. You can, for instance, find the number of days between two dates by simply subtracting the dates from each other.
If you want to get fancier in your date calculations, you can use the DateDiff function. This function allows you, for instance, to determine the number of weeks or months between two dates. In order to use the function to find this type of information, you would do as follows:
iNumWeeks = DateDiff("ww", dFirstDate, dSecondDate) iNumMonths = DateDiff("m", dFirstDate, dSecondDate)
The first line determines the number of weeks between the two dates, and the second determines the number of months between them.
Note:
WordTips is your source for cost-effective Microsoft Word training. (Microsoft Word is the most popular word processing software in the world.) This tip (12380) applies to Microsoft Word 2007, 2010, 2013, and 2016. You can find a version of this tip for the older menu interface of Word here: Determining Differences Between Dates.
Create Custom Apps with VBA! Discover how to extend the capabilities of Office 2013 (Word, Excel, PowerPoint, Outlook, and Access) with VBA programming, using it for writing macros, automating Office applications, and creating custom applications. Check out Mastering VBA for Office 2013 today!
Program a macro, and you can easily find that some lines get very long. If you want to shorten the lines so they are more ...
Discover MoreIf your macro needs to determine the status of the Caps Lock key, you need the code in this tip. Just use the Information ...
Discover MoreInserting a break in your document is easy. You may think that inserting one using a macro is more complex, but it isn't. ...
Discover MoreFREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."
2017-01-23 11:06:11
allen@sharonparq.com
Alex: Note that the tip is about VBA programming (macros). The base date in VBA is, indeed, much different than the base date within Excel itself.
And, this is not a recent change.
-Allen
2017-01-23 09:56:56
Alex Bayman
Interesting - I thought the base date was 1 January 1900. Is this a recent change by Microsoft?
Got a version of Word that uses the ribbon interface (Word 2007 or later)? This site is for you! If you use an earlier version of Word, visit our WordTips site focusing on the menu interface.
Visit the WordTips channel on YouTube
FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."
Copyright © 2024 Sharon Parq Associates, Inc.
Comments