Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 07-24-2019, 03:59 PM
eduzs eduzs is offline Word field last month not working within year change Windows 10 Word field last month not working within year change Office 2010 32bit
Expert
Word field last month not working within year change
 
Join Date: May 2017
Posts: 262
eduzs is on a distinguished road
Default 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}
The problem is when the year changes, so when expected "Dec/2018" I got "01-0,0".
Ps.: My region date format "DD-MM-YYYY", list separator ";".
Any Ideas?
Thanks in advance.
__________________
Backup your original file before doing any modification.
Reply With Quote
  #2  
Old 07-24-2019, 08:36 PM
gmayor's Avatar
gmayor gmayor is offline Word field last month not working within year change Windows 10 Word field last month not working within year change Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,106
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

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
Reply With Quote
  #3  
Old 07-25-2019, 02:24 AM
eduzs eduzs is offline Word field last month not working within year change Windows 10 Word field last month not working within year change Office 2010 32bit
Expert
Word field last month not working within year change
 
Join Date: May 2017
Posts: 262
eduzs is on a distinguished road
Default

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.
Reply With Quote
  #4  
Old 07-25-2019, 05:38 AM
gmayor's Avatar
gmayor gmayor is offline Word field last month not working within year change Windows 10 Word field last month not working within year change Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,106
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

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
Reply With Quote
  #5  
Old 07-25-2019, 04:31 PM
eduzs eduzs is offline Word field last month not working within year change Windows 10 Word field last month not working within year change Office 2010 32bit
Expert
Word field last month not working within year change
 
Join Date: May 2017
Posts: 262
eduzs is on a distinguished road
Default

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:
Originally Posted by gmayor View Post
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.
__________________
Backup your original file before doing any modification.
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Word field last month not working within year change Empty date cell shows wrong month & year Learner7 Excel 3 06-16-2019 11:09 AM
Word field last month not working within year change 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

Other Forums: Access Forums

All times are GMT -7. The time now is 09:04 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft