Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Word CREATEDATE - Minus One Month 1

Status
Not open for further replies.

PWD

Technical User
Jul 12, 2002
823
GB
Hi Peeps. I have a Word Template that has a Table for last month's overtime. I want to have some sort of field format that shows the month before today.

What I have at the moment is
Code:
{DATE \@ "(MMMM)-1 yyyy" \* MERGEFORMAT}
which doesn't do anything in the way that Excel
Code:
=(MONTH(TODAY()))-1
does.

So, today (2nd March 2007) I have to summarise my few paltry hours overtime for last month; so I want the Word document to automatically insert 'February 2007'.

I know I'm just being lazy but surely that's been the spur for a lot of human development?

Any ideas, please?

Des.
 
Since you are being lazy, the answer isn't quite easy either.

Use CREATEDATE field and use a conditional field to insert last month
{IF{CREATEDATE \@ "MM"} = 01 "December" ""}{IF{CREATEDATE \@ "MM"} = 02 "January" ""} etc.


Member- AAAA Association Against Acronym Abusers
 
Hi Des,

The coding for this is fairly complex if you want to do it properly. You need to cope with last month being December last year and the possibility that the calculation will be done on a day whose date is more than the the number of days in last month - which, of course changes for February in a leap year. Here's how it's done:
Code:
{QUOTE
{SET Delay -1}
{SET mm{=MOD(ABS({DATE \@ M}+Delay+11),12)+1}}
{SET yy{=INT({DATE \@ yyyy}+(Delay+{DATE \@ M}-1)/12)}}
{SET dd{=IF(({DATE \@ d}>28)*({mm \@ M}=2)=1,28+((MOD(yy,4)=0)+(MOD(yy,400)=0)-(MOD(yy,100)=0)),IF(({mm \@ M}=4)+({mm \@ M}=6)+({mm \@ M}=9)+({mm \@ M}=11)+({DATE \@ d}>30)>1,30,{DATE \@ d}))}}
"{dd}-{mm}-{yy}" \@ "dddd, d MMMM yyyy"}

You can download the complete field, ready for use, at:
(see under 'Calculate a day, date, month and year, using n months delay').

Cheers
PS: Make sure to read the 'Introductory Notes'.

[MS MVP - Word]
 
Wow. Heavy stuff!!

I just ended up with this:-

Code:
{QUOTE{=MOD({CREATEDATE \@ M}-1,12)}/00 \@MMMM}
Not entirely sure what it all means but it works well out of the Template. Not worried about the January/December problem - I don't get that much overtime!! LOL. I just thought it might be possible to do what I wanted. You never know, it may come in useful for something else I have to do some other time.

Many thanks, and a star!!

Des.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top