Calculating dates in MS-Word

S

Steve

I have sections of a document for Monday, Tuesday, Wednesday, Thursday and
Friday. I have the week begining date in Subject field. How Would I
calculate the headings in the Word document from the Subject field.
Something like Dateadd("D", 1 , Subject)


Steve
 
M

macropod

Hi Steve,

If you bookmark the first date (eg 1stDate), a field coded as per the
following will calculate the second:

{QUOTE
{SET Delay 1}
{SET a{=INT((14-{1stDate \@ M})/12)}}
{SET b{={1stDate \@ yyyy}+4800-a}}
{SET c{={1stDate \@ M}+12*a-3}}
{SET d{1stDate \@ d}}
{SET
jd{=d+INT((153*c+2)/5)+365*b+INT(b/4)-INT(b/100)+INT(b/400)-32045+Delay}}
{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*10^6+mm*10^4+yy \# "00'-'00'-'0000"} \@ "dddd, d MMMM yyyy"}

For the thrid and subsequent dates, you can use a cut-down version of this:

{QUOTE
{SET jd{=jd+Delay}}
{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*10^6+mm*10^4+yy \# "00'-'00'-'0000"} \@ "dddd, d MMMM yyyy"}

in each case. No vba is required. Note that the field braces (ie '{ }') are
created in pairs via Ctrl-F9 - you can't just type them in. Also, to make
life easier, go to:
http://www.wopr.com/cgi-bin/w3t/showthreaded.pl?Number=249902
and download my date calculations tutorial. You can modify the example under
the heading "Calculate a day, date, month and year, using n (301) days
delay" to achieve the above coding. If the date format doesn't suit you
needs, read the instructions under "Date input/output formats" for
instructions on how to change it.

Cheers
PS: You might find that, after saving the document and re-opening it, the
dates will be off. That's becasue the same bookmarks are being used over and
over. The dates will correct themselves if you do anything to cause the
fields to recalculate (eg Ctrl-A followed by F9).
 

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