Search code examples
javascriptjquerysharepointsharepoint-2010

Converting SharePoint date (not datetime) field to do math with?


I want to capture a date on a SharePoint edit form.. then take that date and subtract that date from it to get a value for the number of days. Is this a complicated process or something simple? I'm not having much luck searching due to super secure (and unnecessary) security blocks.


Solution

  • You can use jquery to acheive this and is pretty simple. For eg: see below how to get difference between today and created date of a list item using Jquery.

    var submissionDate = new Date(oListItem.get_item('Created'));
    var today = new Date();
    var diff = today - submissionDate;
    var days = parseInt(diff / 1000 / 60 / 60 / 24);