Calculation from today’s date formatted as years, months, weeks, days
-
Hi there!
I’m trying to calculate the time passed since a specific day (fieldname1) and I want to display it like so:
Eg 1 year 2 months 1 week 1 dayThis is the function I tested on codepen and it works there, but not in CFF:
(function() {
var b = moment(new Date(fieldname1)),
a = moment(new Date()),
intervals = [‘years’,’months’,’weeks’,’days’],
out = [];for(var i=0; i<intervals.length; i++){
var diff = a.diff(b, intervals[i]);
b.add(diff, intervals[i]);
out.push(diff + ‘ ‘ + intervals[i]);
}
return out.join(‘, ‘);
})()Could you please help me a bit?
Thanks!!
The page I need help with: [log in to see the link]
- The topic ‘Calculation from today’s date formatted as years, months, weeks, days’ is closed to new replies.