Display Todays Date in a Calculated Column with Javascript

Here’s what I used to display Today date in a Calculated Column with nothing but JavaScript in SharePoint 2010.

After a lot of research and trial and error, I finally have it displaying:

To display a date like this: 17/5/2015

Use this code:

=CONCATENATE("<p id='mydate'><script>var currentDate = new Date();var day = currentDate.getDate();var month = currentDate.getMonth()+1;var year = currentDate.getFullYear();document.getElementById('mydate').innerHTML = ( day + '/' + month + '/' + year );</script></p>")




Don’t forget to use data type returned as Number(1, 1.0, 100) This will convert the code to HTML

For U.S. Date, just swap the day and month over like this:

( day + ‘/’ + month + ‘/’ + year )

( month + ‘/’ + day + ‘/’ + year )


Update: The above code will only work for the first entry as the id name, i.e. ‘mydate’, needs to be unique.

So all you need to do is use another column that has Unique values, like a counter, or you could even combine two columns as thus:

 =CONCATENATE("<p id='"&PosNum&""&[First Name]&"'><script>var currentDate = new Date();var day = currentDate.getDate();var month = ('0' + (currentDate.getMonth()+1)).slice(-2);var year = currentDate.getFullYear();document.getElementById('"&PosNum&""&[First Name]&"').innerHTML = ( day + '/' + month + '/' + year );</script></p>"

The above code works and displays todays date for every Item.

 Date will now show as 20/05/2015

Hope this saves you some time 😉


8 thoughts on “Display Todays Date in a Calculated Column with Javascript

  1. Mani kandan September 26, 2017 / 8:39 pm

    Hi get the result.

    Thank you..

    But , I want to copy this calToday field to another field DateTime format.

    I want to calculate difference between CalToday and another DateTime datatype field. To calculate overdue.

    • Brett September 27, 2017 / 11:47 am

      Sorry but I don’t know how to use this to calculate overdue date. All this pretty much does is display today’s date in the column.

    • Brett June 29, 2017 / 8:07 pm

      I suppose it would, it’s javascript, so it should work. If you try it, let us know by replying to this comment.

  2. bshsi December 3, 2015 / 4:38 am

    I can’t get this code to work for me. When i entered in the first code, it worked and you were right – it only updated the first item in my list. I tried to use your second code but I keep getting any error. In the two spots where you have [First Name] i have replaced it with a column name in my list. I haven’t touched anything else. When i try to save, i get a message stating “The formula refers to a column that does not exist.”. Am i missing something?

    • Brett December 3, 2015 / 7:36 am

      Yes, the id refers to two columns “&PosNum&””&[First Name]&”. So you’ll need to replace both names. This was to allow a unique ID for each item displaying todays date.

      Also I tried using this method referenced in another calculated column but it wasn’t able to work.
      It seems to be for display purposes only.

      Thanks for trying it out.

      • Nevermind Nonesbusiness February 15, 2017 / 5:22 am

        What was the function of the second column you are referring to – the one indicated above as “&PosNum&”?

      • Brett February 15, 2017 / 7:34 am

        This is to make the column unique otherwise it just displays the date in the first row.
        From my testing, I couldn’t get the date to do anything, it just displays today’s date.
        But thought I would post it in case somebody does find it useful.

Post a Comment

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s