Calculate # of Months between 2 dates
Does anyone have this calculation they can share with me?
Example 1:
Start Date: 1-1-2015
End Date: 12-31-2015
Calculated # of months should equal: "12.00"
Example 2:
Start Date: 1-1-2015
End Date: 1-15-2015
Calculated # of months should equal: "0.5"
I have seen lots of calculations on Podio Help that I have tried to modify - but they have all ended up being inaccurate to some degree or another. Any help would be really great. Thanks.
-
Hi Scott, this should work:
var start = @start date; var end = @end date; var diffMS = end.diff(start) // difference in milliseconds; var diffDur = moment.duration(diffMS); var diffMonth = Math.round(diffDur.asMonths()*10)/10; diffMonth
Results for your examples: 12.00 and 0.50
Rainer
rg@delos-consulting.com -
Sorry, a mistake on my part. Start and end must also be "moments".
Here's the right solution:
var start = moment(@start date); var end = moment(@end date); var diffMS = end.diff(start) // difference in milliseconds; var diffDur = moment.duration(diffMS); var diffMonth = Math.round(diffDur.asMonths()*10)/10; diffMonth
Rainer
-
This was my working solution for my use case:
var start = moment(@Actual Pick Date/Time);
var end = moment(@Actual Drop Date/Time);var diffMS = end.diff(start) // difference in milliseconds;
var diffDur = moment.duration(diffMS);
var diffDay = Math.round(diffDur.asDays()*10)/10;
diffDay + " day(s)" -
@Rainer
Could you take a look at the following question I have?
-
Hello Rainer, Thanks for your efforts. I tried your 'right solution' version that you posted. It sort of works...
If the Start Date is 8-1-2015, and the end date is 12-31-2015 - the calculated answer comes up as "5.10". I would have expected "5".
If I the Start Date is 02-01-2015 and the end date is 12-31-2015 - the answer is "11.10".. so something is off.
Any thoughts on how to fix? Thanks Rainer.
-
Scott , it's a pain to get the right number for months cause a month's length is defined "30 Days".
This would show you 5 for 8/12015 - 12/15/2015
var start = @start date;
var end = @end date;var diffMS = end.diff(start) // difference in milliseconds;
var diffDur = moment.duration(diffMS);
var diffMonth = Math.round(diffDur.asMonths());
diffMonthBut it would you show "5" also for 8/12015 - 12/15/2015 and 8/12015 - 12/25/2015
and "4" for 8/12015 - 12/5/2015What would you expect for:
a) 8/12015 - 12/15/2015
b) 8/12015 - 12/5/2015
c) 8/12015 - 12/25/2015
? -
Rainer, thank you very much!
Strangely, I used the formula and input 180 days with June 8, 2015 as the start date and it returned: April 5, 2027
screenshot: https://www.dropbox.com/s/v5l8yo94fwcggs4/closed-loans.jpg?dl=0
-
@Rainer - I need to calculate a slightly different version of this and was hoping you could help as I've pulled out all my hair! I need to calculate the # of days between a field (@.Last Update) and Today's actual date.
This is what I have, based on this post, but I really need to replace the field @.CreateDate with today's actual date. Any thoughts on how to accomplish this?? Thank you.
var start = moment(@.Last Update);
var end = moment(@.Create Date);var diffMS = end.diff(start) // difference in milliseconds;
var diffDur = moment.duration(diffMS);
var diffDay = Math.round(diffDur.asDays()*10)/10;
diffDay + " day(s)" -
Hi Scott,
for the "today" problem see my comment here https://help.podio.com/hc/en-us/community/posts/115000113951-Trying-return-a-number-on-subtracting-today-s-date-from-a-given-date-in-a-field-?page=1#community_comment_115000105451
Rainer
Please sign in to leave a comment.
Comments
19 comments