How To Display Current Date in a SharePoint 2010 Page

Introduction

In this article we explore how to append today’s date using jQuery, like "weekday,YYYY/MM/dd".

1. In this site add add a Content Editor Web part and select "Edit HTML Source" under the "Format Text" tab.

Content Editor

2. Now edit that Web Part and click on "Click here" to add new content.
3. After that in the Ribbon under editing tools click on "HTML" then in the Ribbon under editing tools click on "HTML Source" under "Format Text" as shown in the figure.

Ribbon under editing tool

4. Then a popup window is opened, 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>
 
5. Let’s see how you can use this to display the current date somewhere in the page like this:

 
current date