difference between 2 dates
I want to have 2 date fields and I want the calculation date to tell me the number of years between those 2. IE 11/13/2006 to 8/27/2015 equals 8.80 years.
-
Entering the following into the calculation field should yield the result your looking for:
var start = moment(@Start Date/Time);
var end = moment(@End Date/Time);
var diffMS = end.diff(start) // difference in milliseconds;
var diffDur = moment.duration(diffMS);
var diffYear = diffDur.asYears();
diffYear -
Hi Hardy,
var
a = moment(@Date 1),
b = moment(@Date 2),
c = b.diff(a,"month"),
d = b.diff(a.add(c,"months"),"days");
c + " month " + d + " days"There's one caveat if both dates are the last day of the month and date day number of date 2 is smaller , e.g date 1 = 08/31/2018 , date 2 = 09/30/2019 - result would be 12 month 30 days. If you want the result 13 months 0 days you need an additional step (var cx and dx):
var
a = moment(@Date 1),
b = moment(@Date),
c = b.diff(a,"month"),
d = b.diff(a.add(c,"months"),"days"),
cx = b.endOf("month").format("DD") == String(d) ? c + 1 : c,
dx = b.endOf("month").format("DD") == String(d) ? 0 : d;
cx + " month " + dx + " days"Rainer
-
Hello Manni,
the notification is shown cause both date fields are empty. Both must be filled to get a result. If one of the date fields is empty the calculation field will show nothing (= empty) in the item view.
Just save the template, enter dates in that item and you'll see that it works and that it returns a result (for a check: go back to the template, enter a blank space at the end of the calculation (that triggers the code and returns the preview) and you'll see that the preview is ok now)
FYI: There are many "error" notifications which give a hint that for the current item (where you opened the template) this calculation doesn't return a valid result. But those notifications don't mean that the code in general is wrong. If you can save it it likely means, that it doesn't work cerrectly for this item. A tip: If you create a code all involved fields should be filled.
Rainer -
Hey Manni,
look at the (red) notification in the lower left corner.
You need to add a new calculation field, copy the code and delete the current calc field.
More about that notification and some calculation field basics you find here
https://help.podio.com/hc/en-us/articles/201019358-Calculations
Rainer -
Very interesting this.
I want to register the Customer Lifetime Value.
Meaning im collecting the Start date for their service (date 1)
But as long as they are not churning or ending their service it is ongoing. Therefor my (date 2) is always "now".
So how can i get Podio to show how many months and years the customer has been paying. im using this for loyalty coins and celebrations. Can Podio help with that ?
Please sign in to leave a comment.
Comments
13 comments