How to calculate a date according to another date in months (not seconds)?

Christine B April 17, 2024

With my ConfiForms macro, I am creating pages in Confluence. These include a date, that is the date of the day of the upload. I have an additional date, that is calculated by adding to the decribed date 10 months. The problem with my approach is that this calculation is done with milli-seconds. Therefore if the current day is April 17, adding 26298000000 milliseconds, results not in February 17, but another date, because not every month has the same number of days, therefore the number of milliseconds, that happen in 10 months vary as well.

Is there a possible adaptation to my calculation, that allows to get a monthy-calculation rather than a calculation in seconds?

 

[entry._now.timestamp.add(26298000000).formatDate(yyyy-MM-dd, Europe/Rome).trimAllSpaces]

1 answer

0 votes
Alex Medved _ConfiForms_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 19, 2024

Hi @Christine B 

Try using the _today variable instead

[entry._today.timestamp.add(26298000000).formatDate(yyyy-MM-dd, Europe/Rome).trimAllSpaces]

It does not have time

Alex 

Christine B April 24, 2024

Hi @Alex Medved _ConfiForms_ 

Thank you for trying, but with this solution I still have the same problem. The problem is, that the calculation should be the number of months and not days or time.

 

Example:

When I create a ConfiForm on April 18, 2024 I want an element that is date January 18, 2025. (Between those dates there are 275 days (=23 760 000 000 milliseconds))

When I create a ConfiForm on Febuary 10, 2024, I want an element is the date November 10, 2024. (Between those dates there are 273 days (=23 587 200 000 milliseconds))

Alex Medved _ConfiForms_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 24, 2024

OK, sorry, now I do understand what is your question. Not sure why you need that and what todo with for example with months that dont have 31 or 30 (Feb), but...

So, I would approach this as follows

[entry._today.formatDate(M).add(10).prepend([entry._today.formatDate(dd)]-).append(-[entry._today.formatDate(yyyy)]).parseDate(dd-M-yyyy).formatDate]

 

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events