If statement with a date

K

Kathy Webster

In a mailmerge doc, I have {MERGEFIELD DateOfLoss}. I do not want the
merged doc to print the DateOfLoss: I want it to print the date 2 years and
1 day AFTER the DateOfLoss. :)
Any takers?
 
M

macropod

Hi Kathy,

To do this you could code your field as:
{QUOTE
{SET MDate {MERGEFIELD DateOfLoss}}
{SET a{=INT((14-{MDate \@ M})/12)}}
{SET b{={MDate \@ yyyy}+4802-a}}
{SET c{={MDate \@ M}+12*a-3}}
{SET d{MDate \@ d}}
{SET jd{=d+INT((153*c+2)/5)+365*b+INT(b/4)-INT(b/100)+INT(b/400)-32044}}
{SET e{=INT((4*(jd+32044)+3)/146097)}}
{SET f{=jd+32044-INT(146097*e/4)}}
{SET g{=INT((4*f+3)/1461)}}
{SET h{=f-INT(1461*g/4)}}
{SET i{=INT((5*h+2)/153)}}
{SET dd{=h-INT((153*i+2)/5)+1}}
{SET mm{=i+3-12*INT(i/10)}}
{SET yy{=100*e+g-4800+INT(i/10)}}
"{dd}-{mm}-{yy}" \@ "dddd, d MMMM yyyy"}

Rather than creating all this yourself, you can download my Date Calc 'tutorial', at:
http://www.wopr.com/cgi-bin/w3t/showthreaded.pl?Number=249902
and modify the example under 'Calculate a day, date, month and year, using n days delay' to suit.

The key changes are:
.. change {SET Delay 14}to {SET MDate {MERGEFIELD DateOfLoss}}
.. change all 'DATE' strings to 'MDate'
.. change '4800' on the 4th line to '4802'
.. change '32045+Delay' on the 7th line to '32044'

Cheers
 
P

Peter Jamieson

macropod's solution is just fine, but if your data source is something like
Access you can also consider using a query to give the right date, which may
help keep the complexity of your Word documents down.

Peter Jamieson
 
K

Kathy Webster

Thank you. There are so many different requirements for different date
scenarios. That's why I need to address the issue in Word rather than in my
access data source. I would love to have Access handle it, since I know
what I'm doing there! :) Unfortunately, I need to build my Word chops.
 
K

Kathy Webster

Yee-hikes! Thank you for doing the heavy lifting!
xxoo

macropod said:
Hi Kathy,

To do this you could code your field as:
{QUOTE
{SET MDate {MERGEFIELD DateOfLoss}}
{SET a{=INT((14-{MDate \@ M})/12)}}
{SET b{={MDate \@ yyyy}+4802-a}}
{SET c{={MDate \@ M}+12*a-3}}
{SET d{MDate \@ d}}
{SET jd{=d+INT((153*c+2)/5)+365*b+INT(b/4)-INT(b/100)+INT(b/400)-32044}}
{SET e{=INT((4*(jd+32044)+3)/146097)}}
{SET f{=jd+32044-INT(146097*e/4)}}
{SET g{=INT((4*f+3)/1461)}}
{SET h{=f-INT(1461*g/4)}}
{SET i{=INT((5*h+2)/153)}}
{SET dd{=h-INT((153*i+2)/5)+1}}
{SET mm{=i+3-12*INT(i/10)}}
{SET yy{=100*e+g-4800+INT(i/10)}}
"{dd}-{mm}-{yy}" \@ "dddd, d MMMM yyyy"}

Rather than creating all this yourself, you can download my Date Calc
'tutorial', at:
http://www.wopr.com/cgi-bin/w3t/showthreaded.pl?Number=249902
and modify the example under 'Calculate a day, date, month and year, using
n days delay' to suit.

The key changes are:
. change {SET Delay 14}to {SET MDate {MERGEFIELD DateOfLoss}}
. change all 'DATE' strings to 'MDate'
. change '4800' on the 4th line to '4802'
. change '32045+Delay' on the 7th line to '32044'

Cheers
--
macropod
[MVP - Microsoft Word]
-------------------------

Kathy Webster said:
In a mailmerge doc, I have {MERGEFIELD DateOfLoss}. I do not want the
merged doc to print the DateOfLoss: I want it to print the date 2 years
and 1 day AFTER the DateOfLoss. :)
Any takers?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top