I added the code below to a SharePoint calculated column in order to get today's date, and it works well, however, I will need to add another calculated column to get the date difference between "Today" and "Last Reported Date".

I have converted the "Last Reported Date" to a number format, and "Today" column is in number format already, but when I add a simple formula

= [today]-[Last Reported Date]

I always get the result


I assume it is because the [today] column, but haven't figured out how to convert the value to a number for calculation

="<img src='/_layouts/images/blank.gif' onload=""{"&"    var today=new Date();"&" var dd=today.getDate();"&"    var mm=today.getMonth()+1;"&"    var yyyy = today.getFullYear();"&"    today=mm+'/'+dd+'/'+yyyy;"&"    this.parentNode.innerHTML=today;"&"}"">"
  • Suggestion: Try doing it first on excel sheet, once you get a correct value there, it should be easy to replicate on SP List. Commented Jun 21, 2017 at 9:23

1 Answer 1


No offense though, But the use of custom HTML markup has been deprecated by Microsoft reflecting from June 2017. So your javascript code will not work any more. you can look for alternatives in a similar thread:

June 13th 2017 Microsoft blocked handling HTML markup in SharePoint calculated fields - how to get the same functionality back


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.