#1
|
|||
|
|||
Word field last month not working within year change
Hi there!
The goal is to list the last 12 months. I have this fields codes which are working fine within the current year: Code:
. . . {QUOTE “01- { ={MOD({Date \@ MM} +10;12)-2 }” \@ MMM/yyyy} {QUOTE “01- { ={MOD({Date \@ MM} +10;12)-1 }” \@ MMM/yyyy} {QUOTE “01- { ={MOD({Date \@ MM} +10;12) }” \@ MMM/yyyy} {QUOTE “01- { ={MOD({Date \@ MM} +10;12)+1 }” \@ MMM/yyyy} Ps.: My region date format "DD-MM-YYYY", list separator ";". Any Ideas? Thanks in advance.
__________________
Backup your original file before doing any modification. |
#2
|
||||
|
||||
See Paul Edstein's (macropod) excellent DateCalc document which you can download from Graham Mayor - Downloads which covers everything you need to know about inserting dates using fields and a lot more that you won't have thought of.
Note that you should use straight quotes rather than smart quotes and as you appear to be using the semicolon list separator rather than the comma, you will have to make some substitutions in his examples.
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
#3
|
|||
|
|||
Hi gmayor, thanks for replying, I already saw macropod document and exhaustively tested the proposed solutions with 'Set Delay, Set M, Set Y... fields' (Set delay to -7, expected 'Dec/2018', got 'jul/2019' or 'dec/2000') and others solutions in google search and nothing seems to work when date calculation involves year change.
__________________
Backup your original file before doing any modification. |
#4
|
||||
|
||||
Assuming UK/Australia pattern date format is used where you live the following will give you the last 12 months from today (page 6 of Paul's document). If you use US format dates then see the preface of Paul's document for the conversion. If you want the last 12 months add a minus sign before the delay values e.g..
{QUOTE{SET Delay -1}{SET m{=MOD({DATE \@ MM}+Delay+11,12)+1}}{SET y{=INT({DATE \@ yyyy}+(Delay+{DATE \@ M}-1)/12)}}"{m}-{y}" \@ "MMMM yyyy"} {QUOTE{SET Delay -2}{SET m{=MOD({DATE \@ MM}+Delay+11,12)+1}}{SET y{=INT({DATE \@ yyyy}+(Delay+{DATE \@ M}-1)/12)}}"{m}-{y}" \@ "MMMM yyyy"} {QUOTE{SET Delay -3}{SET m{=MOD({DATE \@ MM}+Delay+11,12)+1}}{SET y{=INT({DATE \@ yyyy}+(Delay+{DATE \@ M}-1)/12)}}"{m}-{y}" \@ "MMMM yyyy"} {QUOTE{SET Delay -4}{SET m{=MOD({DATE \@ MM}+Delay+11,12)+1}}{SET y{=INT({DATE \@ yyyy}+(Delay+{DATE \@ M}-1)/12)}}"{m}-{y}" \@ "MMMM yyyy"} {QUOTE{SET Delay -5}{SET m{=MOD({DATE \@ MM}+Delay+11,12)+1}}{SET y{=INT({DATE \@ yyyy}+(Delay+{DATE \@ M}-1)/12)}}"{m}-{y}" \@ "MMMM yyyy"} {QUOTE{SET Delay -6}{SET m{=MOD({DATE \@ MM}+Delay+11,12)+1}}{SET y{=INT({DATE \@ yyyy}+(Delay+{DATE \@ M}-1)/12)}}"{m}-{y}" \@ "MMMM yyyy"} {QUOTE{SET Delay -7}{SET m{=MOD({DATE \@ MM}+Delay+11,12)+1}}{SET y{=INT({DATE \@ yyyy}+(Delay+{DATE \@ M}-1)/12)}}"{m}-{y}" \@ "MMMM yyyy"} {QUOTE{SET Delay -8}{SET m{=MOD({DATE \@ MM}+Delay+11,12)+1}}{SET y{=INT({DATE \@ yyyy}+(Delay+{DATE \@ M}-1)/12)}}"{m}-{y}" \@ "MMMM yyyy"} {QUOTE{SET Delay -9}{SET m{=MOD({DATE \@ MM}+Delay+11,12)+1}}{SET y{=INT({DATE \@ yyyy}+(Delay+{DATE \@ M}-1)/12)}}"{m}-{y}" \@ "MMMM yyyy"} {QUOTE{SET Delay -10}{SET m{=MOD({DATE \@ MM}+Delay+11,12)+1}}{SET y{=INT({DATE \@ yyyy}+(Delay+{DATE \@ M}-1)/12)}}"{m}-{y}" \@ "MMMM yyyy"} {QUOTE{SET Delay -11}{SET m{=MOD({DATE \@ MM}+Delay+11,12)+1}}{SET y{=INT({DATE \@ yyyy}+(Delay+{DATE \@ M}-1)/12)}}"{m}-{y}" \@ "MMMM yyyy"} {QUOTE{SET Delay -12}{SET m{=MOD({DATE \@ MM}+Delay+11,12)+1}}{SET y{=INT({DATE \@ yyyy}+(Delay+{DATE \@ M}-1)/12)}}"{m}-{y}" \@ "MMMM yyyy"} which produces June 2019 May 2019 April 2019 March 2019 February 2019 January 2019 December 2018 November 2018 October 2018 September 2018 August 2018 July 2018 Copy the field code sequence from Paul's document or use Import and export field constructions as text to restore the fields.
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
#5
|
|||
|
|||
Works like a charm! Thanks gmayor!
I just needed to change the list separator and the delay to get last 12 months (0, -1, -2, -3...). Quote:
__________________
Backup your original file before doing any modification. |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Empty date cell shows wrong month & year | Learner7 | Excel | 3 | 06-16-2019 11:09 AM |
can i make a dropdown style calender to select the month and year to enter vacation time taken | jamesbriese | Excel | 1 | 12-06-2016 01:00 PM |
Excel day date month year Function | greginky | Excel | 1 | 01-05-2016 02:19 AM |
Macro now fails in Word 2013 after working for more than a year; still works in 2007 | cyraxote | Word VBA | 10 | 09-05-2015 12:33 AM |
Formula to count entries as per month, year and submission wise from different sheets | pinkacidpunk | Excel | 1 | 05-28-2013 08:26 AM |