View Full Version : Converting a date to its number equivalent
Bob789
05-22-2017, 05:07 PM
In a mail merge switch when I insert a mail merge field that is a date like 05/22/2017 I want to convert it to its number equivalent. That is I want 05/22/2017 to convert to 42877. Can anyone help me with this? Thanks
macropod
05-22-2017, 06:26 PM
To see how to do this and just about everything else you might want to do with dates in Word, check out my Microsoft Word Date Calculation Tutorial, at:
http://windowssecrets.com/forums/showthread.php/154368-Microsoft-Word-Date-Calculation-Tutorial
or:
http://www.gmayor.com/downloads.htm#Third_party
In particular, look at the item titled Convert a Gregorian Calendar Date to a Julian Day Number. Do read the document's introductory material.
For your purposes, you'll need to change the 32045 in the field code to 2447064
Bob789
05-22-2017, 09:26 PM
Thank you Paul. I will take a look at this. Something tells me it's going to be very complicated.
macropod
05-22-2017, 09:47 PM
Something tells me it's going to be very complicated.
For the most part, it's a copy/paste exercise. The field code in the tutorial is:
{QUOTE
{SET a{=INT((14-{DATE \@ M})/12)}}
{SET b{={DATE \@ yyyy}+4800-a}}
{SET c{={DATE \@ M}+12*a-3}}
{SET d{DATE \@ d}}
{SET jd{=d+INT((153*c+2)/5)+365*b+INT(b/4)-INT(b/100)+INT(b/400)-32045}}
{jd \# ,0}}
You'd copy that from the tutorial into your mailmerge main document, then edit the field code to read:
{QUOTE
{SET a{=INT((14-{MERGEFIELD MyDate \@ M})/12)}}
{SET b{={MERGEFIELD MyDate \@ yyyy}+4800-a}}
{SET c{={MERGEFIELD MyDate \@ M}+12*a-3}}
{SET d{MERGEFIELD MyDate \@ d}}
{SET jd{=d+INT((153*c+2)/5)+365*b+INT(b/4)-INT(b/100)+INT(b/400)-2447064}}
{jd \# ,0}}
where 'MyDate' is the field name in your data source.
Bob789
05-22-2017, 10:16 PM
Thank you again Paul. This looks exactly what I am looking for. Wow, wild calculation but I will do as you recommend and past this formula into my document and change where appropriate with my mail merge field. Really appreciate it.
macropod
05-22-2017, 10:22 PM
Wow, wild calculation
And that's one of the simpler ones...
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.