Hello. Using code found on this site by macropod, I have been able to do almost everything I need. however, I am stuck in one thing. The code to display a calculated date n days away, works perfectly when I need something more than 23 days out, but whenever I select a range less than 23 days I am getting seemingly random months and always the 12th. I need it to display a date 14 days from the date the document is open. Anyone have a fix for this? Thank you!
![]() |
Patch reliability is unclear, but widespread attacks make patching prudent. Go ahead and patch, but watch out for potential problems. |
SIGN IN | Not a member? | REGISTER | PLUS MEMBERSHIP |
-
Date calculations in Word
Home » Forums » AskWoody support » Productivity software by function » MS Word and word processing help » Date calculations in Word
- This topic has 14 replies, 4 voices, and was last updated 9 years, 7 months ago.
AuthorTopicWStveglahn
AskWoody LoungerNovember 20, 2015 at 8:03 am #503252Viewing 8 reply threadsAuthorReplies-
RetiredGeek
AskWoody_MVPNovember 20, 2015 at 10:01 am #1538250Tveglahn,
Press Ctrl+F9
In between the brackets type: Date+14
42703-WordDateFormula
Click the Update button
42702-WordDateResultYou can use Alt+F9 to toggle between seeing the formula and seeing the result.
HTH :cheers:
-
Charles Kenyon
AskWoody LoungerNovember 20, 2015 at 12:41 pm #1538280Tveglahn,
Press Ctrl+F9
In between the brackets type: Date+14
42703-WordDateFormula
Click the Update button
42702-WordDateResultYou can use Alt+F9 to toggle between seeing the formula and seeing the result.
HTH :cheers:
Nope. Field maths for dates are much more complex than this. The calendar based on Roman Emporers and moon cycles is not designed for simple calculations. See my page or Paul’s tutorial.
Here is a field that gives you the date 14 days in advance based on the CREATEDATE.
Code:{ QUOTE "{ SET " Delay" "14" } { SET "DaysInMonth" { IF { CreateDate @ "MM" } 2 { = ROUND(30.575*{ CreateDate @ "MM" },0)- ROUND(30.575*{ = { CreateDate @ "MM" } -1 },0) } { IF { = MOD( { CreateDate @"yy" } , 4 ) } > 0 "28" "29" } } } { SET "NextMonth" { IF { CreateDate @ "MM" } = 12 "1/97" "{ = { CreateDate @ "MM" } + 1 }/97 } } { IF { = { REF "Delay" } + { CreateDate @ "dd" } } <= { REF"DaysInMonth" } { CreateDate @ "MMMM { = { REF "Delay" } + { CreateDate @ "dd" } }, yyyy"}{ QUOTE { NextMonth @ "MMMM" } { = { REF "Delay" } + { CreateDate @ "dd" } - { REF"DaysInMonth" } }, { IF { CreateDate @ "MM" } 12 { CreateDate @ "yyyy" } { CreateDate @ "{ = 1 + { CreateDate @ "yyyy" } # "xxxx" }" } } } }" }
-
-
WStveglahn
AskWoody Lounger -
RetiredGeek
AskWoody_MVPNovember 20, 2015 at 11:01 am #1538263Tveglahn,
Ok, here’s one that actually gets the right date but it’s a little complicated.
It requires a Macro placed in the ThisDocument module:
Code:Option Explicit Private Sub Document_Open() On Error GoTo JustSetValue ActiveDocument.Variables.Add Name:="TwoWeeks", _ Value:=Format(DateAdd("d", 14, Now()), "mm/dd/yy") On Error GoTo 0 GoTo GetOut JustSetValue: ActiveDocument.Variables("TwoWeeks").Value = Format(DateAdd("d", 14, Now()), "mm/dd/yy") GetOut: End Sub 'Document_Open
Then in your document:
42704-WordDateFormulaResult:
42705-WordDateResultNote: This will update everytime you open the document UNLESS you hold down the Ctrl key while opening the document. If you don’t want this behavior we’ll have to refine this some by calculating against something like the Document Creation Date.
Test File:
HTH :cheers:
-
Charles Kenyon
AskWoody LoungerNovember 20, 2015 at 12:43 pm #1538281Tveglahn,
Ok, here’s one that actually gets the right date but it’s a little complicated.
It requires a Macro placed in the ThisDocument module:
Code:Option Explicit Private Sub Document_Open() On Error GoTo JustSetValue ActiveDocument.Variables.Add Name:="TwoWeeks", _ Value:=Format(DateAdd("d", 14, Now()), "mm/dd/yy") On Error GoTo 0 GoTo GetOut JustSetValue: ActiveDocument.Variables("TwoWeeks").Value = Format(DateAdd("d", 14, Now()), "mm/dd/yy") GetOut: End Sub 'Document_Open
Then in your document:
42704-WordDateFormulaResult:
42705-WordDateResultNote: This will update everytime you open the document UNLESS you hold down the Ctrl key while opening the document. If you don’t want this behavior we’ll have to refine this some by calculating against something like the Document Creation Date.
Test File:
HTH :cheers:
For this, and many purposes, fields are superior to vba. Primarily because they operate in a macro-free environment. On the other hand, vba has much of the date calculation built into it, which the fields do not.
-
-
-
RetiredGeek
AskWoody_MVPNovember 20, 2015 at 10:32 am #1538259 -
WStveglahn
AskWoody Lounger -
RetiredGeek
AskWoody_MVPNovember 20, 2015 at 12:30 pm #1538276Tveglahn,
Could you post a test document with your current method? :cheers:
-
Charles Kenyon
AskWoody LoungerNovember 20, 2015 at 12:39 pm #1538279Paul (macropod)’s fields work very well. They have been field-tested for years. Read through the tutorial again, especially the beginning.
Myweb page on calculated dates predates that tutorial. It has a field which is set for 14 days ahead but you would need to change the createdate field to a date field.
Code:{ QUOTE "{ SET " Delay" "14" } { SET "DaysInMonth" { IF { CreateDate @ "MM" } 2 { = ROUND(30.575*{ CreateDate @ "MM" },0)- ROUND(30.575*{ = { CreateDate @ "MM" } -1 },0) } { IF { = MOD( { CreateDate @"yy" } , 4 ) } > 0 "28" "29" } } } { SET "NextMonth" { IF { CreateDate @ "MM" } = 12 "1/97" "{ = { CreateDate @ "MM" } + 1 }/97 } } { IF { = { REF "Delay" } + { CreateDate @ "dd" } } <= { REF"DaysInMonth" } { CreateDate @ "MMMM { = { REF "Delay" } + { CreateDate @ "dd" } }, yyyy"}{ QUOTE { NextMonth @ "MMMM" } { = { REF "Delay" } + { CreateDate @ "dd" } - { REF"DaysInMonth" } }, { IF { CreateDate @ "MM" } 12 { CreateDate @ "yyyy" } { CreateDate @ "{ = 1 + { CreateDate @ "yyyy" } # "xxxx" }" } } } }" }
I recommend sticking withPaul’s tutorial though. Typing the field in by hand can be a real bear and his are already in Word format.
-
WStveglahn
AskWoody LoungerNovember 20, 2015 at 2:45 pm #153829342708-Picture242707-Picture1I’ve been using macropod’s (paul’s) code, and as I said, it works great for my need for a date 60 days out. but whenever I use it for only 14 days out I’m getting bad dates. Anything between 11 and 23 days is only returning the 12th of a seemingly random month. Less than 10 days or more than 23 days works fine. That’s why I started this, because I didn’t know if a workaround was needed…. Here is what I am using so far. Notice how the first date should be 14 days from today, but is showing april 12th instead.
-
WStveglahn
AskWoody LoungerNovember 20, 2015 at 4:33 pm #1538308not sure why it is taking 2 very different codes to do the same thing for different days… but the following code seems to work. Let me know if you see anything that im missing. I’ll know for sure tomorrow when I open the doc back up and see if they update for the new day *smile*
42709-working-code42710-working-resultsI appreciate all the help and responses!
-
-
RetiredGeek
AskWoody_MVPNovember 20, 2015 at 5:21 pm #1538309tveglahn,
I have one word for you…MAINTENANCE!
Make sure you document what you are doing line by line. Six months from now you may have trouble remembering what it all does, I’d probably have trouble tomorrow!
That is the advantage of the VBA much less complicated. Create a template with the VBA code and create documents from that and the user don’t have to worry about it. You could even write VBA code to insert the field codes at the cursor.
HTH :cheers:
-
macropod
AskWoody_MVPNovember 20, 2015 at 6:11 pm #1538369Hello. Using code found on this site by macropod, I have been able to do almost everything I need. however, I am stuck in one thing. The code to display a calculated date n days away, works perfectly when I need something more than 23 days out, but whenever I select a range less than 23 days I am getting seemingly random months and always the 12th. I need it to display a date 14 days from the date the document is open. Anyone have a fix for this? Thank you!
Did you read the tutorial’s Introduction, especially the part to do with regional date settings?
Cheers,
Paul Edstein
[Fmr MS MVP - Word] -
WStveglahn
AskWoody Lounger
-
Viewing 8 reply threads -

Plus Membership
Donations from Plus members keep this site going. You can identify the people who support AskWoody by the Plus badge on their avatars.
AskWoody Plus members not only get access to all of the contents of this site -- including Susan Bradley's frequently updated Patch Watch listing -- they also receive weekly AskWoody Plus Newsletters (formerly Windows Secrets Newsletter) and AskWoody Plus Alerts, emails when there are important breaking developments.
Get Plus!
Welcome to our unique respite from the madness.
It's easy to post questions about Windows 11, Windows 10, Win8.1, Win7, Surface, Office, or browse through our Forums. Post anonymously or register for greater privileges. Keep it civil, please: Decorous Lounge rules strictly enforced. Questions? Contact Customer Support.
Search Newsletters
Search Forums
View the Forum
Search for Topics
Recent Topics
-
Is it Local or is it Microsoft Account?
by
RetiredGeek
55 minutes ago -
Does Your State Reveal Who’s Been Hacked?
by
Nibbled To Death By Ducks
11 hours, 43 minutes ago -
A one-year extension to Windows 10 — almost free!
by
Susan Bradley
32 minutes ago -
Windows Configuration Update (KB5062324) – June 2025
by
Alex5723
11 hours, 39 minutes ago -
A federal judge sides with Anthropic in lawsuit over training AI
by
Alex5723
16 hours, 36 minutes ago -
Name of MS Word Formatting Feature
by
John Baum
5 hours, 23 minutes ago -
InControl Failure?
by
Casey H
3 hours, 45 minutes ago -
Microsoft : Free 1 year support for Windows 10 after EOL
by
Alex5723
5 hours, 28 minutes ago -
MS-DEFCON 3: Businesses must tread carefully
by
Susan Bradley
6 hours, 52 minutes ago -
McLaren Health Care says data breach impacts 743,000 patients
by
Nibbled To Death By Ducks
1 day, 15 hours ago -
WhatsApp banned on House staffers’ devices
by
Alex5723
1 day, 10 hours ago -
Is your device eligible?
by
Susan Bradley
1 day, 18 hours ago -
Windows 11 Insider Preview build 26200.5661 released to DEV
by
joep517
2 days ago -
Windows 11 Insider Preview build 26120.4452 (24H2) released to BETA
by
joep517
2 days ago -
Hello Windows…My Problem is Windows Hello…
by
rdleib
2 days, 2 hours ago -
New Canon Printer Wants Data Sent
by
Win7and10
2 days, 2 hours ago -
I set up passkeys for my Microsoft account
by
Lance Whitney
31 minutes ago -
AI is for everyone
by
Peter Deegan
2 days, 1 hour ago -
Terabyte update 2025
by
Will Fastie
1 day, 19 hours ago -
Migrating from Windows 10 to Windows 11
by
Susan Bradley
3 hours, 13 minutes ago -
Lost sound after the upgrade to 24H2?
by
Susan Bradley
20 hours, 15 minutes ago -
How to move 10GB of data in C:\ProgramData\Package Cache ?
by
Alex5723
1 day, 4 hours ago -
Plugged in 24-7
by
CWBillow
2 days, 11 hours ago -
Netflix, Apple, BofA websites hijacked with fake help-desk numbers
by
Nibbled To Death By Ducks
3 days, 14 hours ago -
Have Copilot there but not taking over the screen in Word
by
CWBillow
3 days, 11 hours ago -
Windows 11 blocks Chrome 137.0.7151.68, 137.0.7151.69
by
Alex5723
5 days, 5 hours ago -
Are Macs immune?
by
Susan Bradley
1 day, 20 hours ago -
HP Envy and the Function keys
by
CWBillow
4 days, 13 hours ago -
Microsoft : Removal of unwanted drivers from Windows Update
by
Alex5723
2 days, 6 hours ago -
MacOS 26 beta 1 dropped support for Firewire 400/800
by
Alex5723
5 days, 16 hours ago
Recent blog posts
Key Links
Want to Advertise in the free newsletter? How about a gift subscription in honor of a birthday? Send an email to sb@askwoody.com to ask how.
Mastodon profile for DefConPatch
Mastodon profile for AskWoody
Home • About • FAQ • Posts & Privacy • Forums • My Account
Register • Free Newsletter • Plus Membership • Gift Certificates • MS-DEFCON Alerts
Copyright ©2004-2025 by AskWoody Tech LLC. All Rights Reserved.