Increment only year in a date, via script

Good morning, and Good New Year !
Help me, please.
With FM Pro 18 (Windows) I have a “DEADLINE” table with a Date field named “Due_Date” that contains the due date 12/31/2024.
I want to change - via script - only the year from 2024 to 2025, while keeping the Day and Month of the existing date.
I tried “Replace Field Content" - Replace with:
Day(Deadline::Due_Date);Month(Deadline::Due_Date);Year((Deadline::Due_Date) + 1)
But unfortunately it doesn't work.
Can you suggest me the right syntax to achieve this modification ?
Thank you in advance.
gigi1936

Welcome to The Soup.

Try Date (month; day; year).

1 Like

It does not work. I obtain a long long number ....

set variable $NewDate = Date( Month(Due_Date), Day(Due_Date), Year(Due_Date) + 1)

or to use your Replace Field Content, it would look like this:

Replace Field Content
Date( Month(Deadline::Due_Date); Day(Deadline::Due_Date); Year(Deadline::Due_Date) + 1)

You have the Month and Day swapped, and need to enclose the entire expression within the Date() function. Also, you had the +1 inside the wrong parenthesis group.

1 Like

Set variable $date24 (table::field)
Set variable $date25 ($date24 + 365)
Set field (table::field ; $date25)

Another way to do it - the reason this works is that Dates are internally stored as the # of days since a certain timepoint.

One problem with this solution would be leap years - March 1st + 365 would be February 29th of the next year, if the next year is a leap year.

1 Like

Yes, in a Leap Year the script would have to add 366 days.

I'm not sure what the "right" answer is in all cases.

For example, what is "one year after February 29th, 2028" ?

1 Like

I thank all of you dear friends for your suggestions.
I have considered all the difficulties you have presented to me, especially the one related to leap years, which is really serious.
At this point I have decided to do the year increment manually, intervening directly on the expiration date. It is a quick, clean, and hassle-free operation.
Thanks again, and Happy New Year 2025 to all of you.
Gigi1936

1 Like

Set a variable to the first day in March, then subtract 1. If the resulting day is 29, it’s a leap year. If the result is 28, it’s a “normal” year.

4 Likes

Alternative: 29 = day ( date ( 2 ; 29 ; some_year ) )

:wink:

1 Like

For annual/yearly date stuff like this, I (almost) always go to the 1st of the next month and subtract 1 as mentioned by @steverichter , above. There are different ways and places to apply it, but it's the most reliable method for me, as it always gets it right, leap or not.

I like what @Malcolm is offering above. Nice and compact if one is needing to address leap year. :+1:

Well, I apply formula DATE(Month-Day-Year +1) (with the right syntax) suggested by xochi, and it works like a charm. No matter if are involved leap years. An anniversary is an anniversary, the Day and the Month are "fixed" and not "calculated": see Xmas, that is always on 25th December, leap and not leap.
OK, Happy New Year to all
gigi1936