How to display current date in SharePoint 2010 Page?

InfoPath alternatives for form designing SharePoint

Here we will discuss how we can display current date and time using javascript and jQuery in SharePoint page. We can use JavaScript/jQuery code inside a content editor web part. If you want show current date and time in SharePoint 2013/2016 page, then you can embed the code inside a script editor web part.

Read some SharePoint tutorials

SharePoint Server 2016 Installation FREE PDF guide

Export SharePoint designer List workflow from one site to another site

Update or Delete SharePoint 2010 List Item using Javascript Object Model

Here we will append today’s date in the SharePoint page using jQuery like “weekday, YYYY/MM/dd”.

For this follow below steps:

– Edit the SharePoint page and then Add a Content Editor Web Part like below:

display current date in javascript
display current date in javascript

– Now edit that Web Part and click on Click here to add new content.



– After this On Ribbon under editing tools click on HTML after this On Ribbon under editing tools click on HTML Source under Format Text shown in fig.

display current date in javascript in sharepoint
display current date in javascript in sharepoint

– After this one popup window is open, under this window add the following code.

<script src=”/JS/jquery-1.3.2.min.js” type=”text/javascript”></script>

<script language=”javascript” type=”text/javascript”>

function strpad00(s) {

s = s + ”;

if (s.length === 1) s = ‘0’ + s;

return s;

}

$(document).ready(function () {

var weekday = new Array(7);

weekday[0] = “Sunday”;

weekday[1] = “Monday”;

weekday[2] = “Tuesday”;

weekday[3] = “Wednesday”;

weekday[4] = “Thursday”;

weekday[5] = “Friday”;

weekday[6] = “Saturday”;

var now = new Date();

var n = weekday[now.getDay()];

var currentDate = now.getFullYear() + “/” + strpad00(now.getMonth() + 1) + “/” + strpad00(now.getDate());

$(‘.s4-pagedescription’).append(“<div style=’float:right’>” + n + “,” + currentDate + “</div>”);

});

</script>


– Now Save the page and the date will appear like below:

display current date and time in html using javascript
display current date and time in html using javascript

Hope this article will be helpful.


You May Also like the Following SharePoint Online Tutorials:

About Sagar Pardeshi

I am Developer working on Microsoft Technologies for the past 6+years. I am very much passionate about programming and my core skills are SharePoint, ASP.NET & C#,Jquery,Javascript,REST. I am running this blog to share my experience & learning with the community I am an MCP, MCTS .NET & Sharepoint 2010, MCPD Sharepoint 2010, and MCSD HTML 5,Sharepoint 2013 Core Solutions. I am currently working on Sharepoint 2010, MOSS 2007, Sharepoint 2013,Sharepoint 2013 App Dev, C#, ASP.NET, and SQL Server 2008.

View all posts by Sagar Pardeshi →

Leave a Reply