Skip to main content

Search

Calculated expression to get the number of days from a column until today

Comments

3 comments

  • eiben

    Hi Jay,

    try this:

    // load the moment.js library from whereever you need it
    var url = "https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.18.1/moment.js";
    var fileName = "momentjs";
    var moduleCache = window.module;
    var defineCache = window.define;
    window.module = undefined;
    window.define = undefined;
    window.SP.SOD.registerSod(fileName, url);
    window.LoadSodByKey(fileName, null, true);
    window.module = moduleCache;
    window.define = defineCache;

    //parse the "Date reported" field with moment.js
    var dateReported = moment([[DateReported]]);
    var today = moment();

    //calculate the difference in days
    return today.diff(dateReported, "days");

     

    0
  • JayT

    Now I'm getting this error when trying to evaluate "Error occurred on evaluating expression. Reference window is not defined at line 4"

    I don't understand why that error is showing up now. Any thoughts?

    -Jay

    0
  • eiben

    That is really strange. I just used your script as a starting point and tweaked the last few lines. When I paste this into the expression-editor as a function it works just as expected.

    0

Please sign in to leave a comment.