Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 09-02-2020, 08:42 AM
eduzs eduzs is offline Field code for last day of the month Windows 10 Field code for last day of the month Office 2019
Expert
Field code for last day of the month
 
Join Date: May 2017
Posts: 262
eduzs is on a distinguished road
Default Field code for last day of the month


Hi there!
Please, does anyone have a field code that returns:
1) The last day of the last month prior to the current date?
2) The last day of the month of a given date.
I looked at the document DateCalc V2_86, but those field codes is a little complicated to modify.
Thanks.
__________________
Backup your original file before doing any modification.
Reply With Quote
  #2  
Old 09-02-2020, 09:18 AM
eduzs eduzs is offline Field code for last day of the month Windows 10 Field code for last day of the month Office 2019
Expert
Field code for last day of the month
 
Join Date: May 2017
Posts: 262
eduzs is on a distinguished road
Default

For the 1st question, this seems to work (need to do more tests):

{QUOTE {SET Delay 0}{SET a{=INT((14-{DATE \@ M})/12)}}{SET b{={DATE \@ yyyy}+4800-a}}{SET c{={DATE \@ M}+12*a-3}}{SET d = 1 }{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}-{mm}-{yy}" \@ "d/M/yyyy"}

For the 2nd question, if I change "DATE" to "DOCVARIABLE mydate" it not work, cause in this situation the delay should be count from the 1st day of the next month before mydate, and not the 1st day of the current month.
__________________
Backup your original file before doing any modification.
Reply With Quote
  #3  
Old 09-02-2020, 07:29 PM
Charles Kenyon Charles Kenyon is offline Field code for last day of the month Windows 10 Field code for last day of the month Office 2019
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,140
Charles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant future
Default

From Paul's tutorial. Microsoft Word Date Calculation Tutorial
Question 1
Code:
{QUOTE
{SET Subtract 0}
{SET Offset -1}
{SET mm{=MOD({Date \@ MM}+MOD(Offset,12)+11,12)+1}}
{SET yy{=INT({DATE \@ yyyy}+({DATE \@ M}+Offset-1)/12)}}
{SET dd{=MAX(1,IF((mm=2),28+(MOD(yy,4)=0)+(MOD(yy,400)=0)-(MOD(yy,100)=0),IF((mm=4)+(mm=6)+(mm=9)+(mm=11)+({DATE \@ d}>30)=1,30,31))-Subtract)}}
"{mm}-{dd}-{yy}" \@ "dddd, d MMMM yyyy"}

Question 2

For the second question, use a Date Picker CC and bookmark it. Pick the date and substitute a reference to the bookmark in the above field for the DATE field. The Offset is set to 0 since it is the same month.

Here is with the bookmark being named "MyDate."
Code:
{QUOTE
{SET Subtract 0}
{SET Offset 0}
{SET mm{=MOD({MyDate \@ MM}+MOD(Offset,12)+11,12)+1}}
{SET yy{=INT({MYDATE \@ yyyy}+({MYDATE \@ M}+Offset-1)/12)}}
{SET dd{=MAX(1,IF((mm=2),28+(MOD(yy,4)=0)+(MOD(yy,400)=0)-(MOD(yy,100)=0),IF((mm=4)+(mm=6)+(mm=9)+(mm=11)+({MYDATE \@ d}>30)=1,30,31))-Subtract)}}
 "{mm}-{dd}-{yy}" \@ "dddd, d MMMM yyyy"}
Here is a temporary link to a document containing the two fields and the DatePicker marked with a bookmark.
Dropbox - deleteme.docx - Simplify your life
Reply With Quote
  #4  
Old 09-03-2020, 08:35 PM
Charles Kenyon Charles Kenyon is offline Field code for last day of the month Windows 10 Field code for last day of the month Office 2019
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,140
Charles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant future
Default

Are the fields I provided doing what you want? You may have to change the formatting at the end.
Reply With Quote
  #5  
Old 09-04-2020, 09:42 AM
eduzs eduzs is offline Field code for last day of the month Windows 10 Field code for last day of the month Office 2019
Expert
Field code for last day of the month
 
Join Date: May 2017
Posts: 262
eduzs is on a distinguished road
Default

I can't download files .
I managed to reach the 2nd answer by calculating the 1st day of the following month and subtracting 1 day:
Thanks!
__________________
Backup your original file before doing any modification.
Reply With Quote
  #6  
Old 09-04-2020, 11:19 AM
Charles Kenyon Charles Kenyon is offline Field code for last day of the month Windows 10 Field code for last day of the month Office 2019
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,140
Charles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant future
Default

Are you saying you can't download any files, or just the one I linked?
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Field code for last day of the month Word field last month not working within year change eduzs Word VBA 4 07-25-2019 04:31 PM
Field code for last day of the month VBA Code to search for field codes with certain text before the Field code and to change style welcometocandyland Word VBA 4 02-08-2017 06:53 PM
Word Field Code Displays Prior Month jadenmyboy Word 1 09-01-2015 12:29 PM
Formula to subtract one month from due date field in reminder field ghumdinger Outlook 1 10-01-2011 12:09 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 03:24 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