• Resolved andxres

    (@andxres)


    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 day

    This 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]

Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Calculation from today’s date formatted as years, months, weeks, days’ is closed to new replies.