Skip to main content
SuziS_UK
Participating Frequently
June 6, 2019
Question

Calculate whole or part months, Adobe pro 2017

  • June 6, 2019
  • 1 reply
  • 430 views

Hello again,

I am trying to calculate how many whole or part months there are between two dates, chosen with a date picker so the dates are not fixed.

I have scoured this forum and the web in general but I can't find an example that closely enough matches my problem, which I think is quite straigthforward, however I'm just learning js and quite a novice.

I have two date fields:  StartDate and EndDate.

I have a third field (Duration) where I'd like the number of months or part months between these dates to be displayed.

I have looked at the various links posted in other people's questions but none of these seem to answer my problem becuase there's often some other complication which they need help with, such as needing a particular time zone, or particular format.

Please can anyone help?

TIA,

Su

This topic has been closed for replies.

1 reply

try67
Community Expert
Community Expert
June 6, 2019

This is not so simple as it sounds... And you also need to use a specific format for your date fields.

Here's the general outline of how I would do it:

- Convert both strings to Date objects.

- Change the date of the Start Date object to the first of the month.

- Define a counter and set it to zero.

- In a loop, add 1 month at a time to the Start Date object, until the month and year of the Start Date and End Date are the same.

Increment the counter's value by one in each iteration.

- The end result is the value of the counter variable.