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

@Rainer

Your Solution failed to work for me... Podio comes back with "Script error: TypeError: undefined is not a function"
var pick = @Actual Pick Date/Time;
var drop = @Actual Drop Date/Time;
var diffMS = drop.diff(pick);
var diffDur = moment.duration(diffMS);
diffDur

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)"

Mitchell,

simply:
var start = moment(@start date);
var end = moment(@end date);

`````` end.diff(start,"days")
``````

or more exactly: use my other calculation, but instead of "asMonths" enter "asDays".

Rainer

Thanks for the simplification @Rainer !!!

Mitch

@Rainer

Could you take a look at the following question I have?

https://help.podio.com/hc/communities/public/questions/204618718-Using-a-contains-function-in-conjunction-with-a-switch-case

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());
diffMonth

But 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/2015

What would you expect for:
a) 8/12015 - 12/15/2015
b) 8/12015 - 12/5/2015
c) 8/12015 - 12/25/2015
?

Thanks Rainer. I knew dates were tricky but thought someone would have worked something out to address the problem.

I actually tried your last calc but Podio gave me "Script Error; Type Error; undefined is not a function". ??

Always the same mistake, shouldn't only coypy & paste. Start and end must also be "moments".:

var start = moment(@start date);
var end = moment(@end date);

I am the king of Copy/Paste. :-)

Thanks for the clarification... I will try it out.

What about if you have a contract that starts on a date and expires 180 days from the start date, and you want the calculation field to tell you what the date of expiration is?

Expressed like this:

var1=(@start_date)
var2=(@duration_days)

result = Date of expiration

Hi James,

``````var date  = @startdate ;
var durD = @durationdays;

``````

One tip: Numbers are not allowed as first characters in var names. So can't do var = 1 or var var = 1a, but var = a1.

Rainer

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

Values from a duration field are always given back as hours. So it calculates var durD = 180*24.
Change var durD to : @duration/24

@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)"

Thanks Rainer, I will check it out.  Much appreciated!  Have a great day!