0

I made a report page for our call desk. The page will be printed and be used by management. So preferably i have in the page on top inside a text field a script snippet to shown the date as when this page was printed. So i get something like

Ticket system report of 4/12/2016 (or some other day format).

I tried the code below as script content, but it doesn't seam to work. It was originally written for 2010, and i am using SharePoint 2013 so maybe i need a different 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>");

    });

Peter
  • 193
  • 3
  • 19

2 Answers2

0

Make sure you have configured JQuery libraries in your SharePoint instance.

Second, the date is getting appended to an element with style s4-pagedescription.. Since it 2013 I believe this element doesn't exists. So you can add similar element to the page

<div class='s4-pagedescription' />

If you don't want to use jQuery then change below

$(document).ready(function () {

To

window.onload = function(){

Then change $('.s4-pagedescription').append("<div style='float:right'>" + n + "," + currentDate + "</div>");}); to

document.getElementById("s4-pagedescription").innerHTML = currentDate;

Also add below at the end after closing script tag..

<div id='s4-pagedescription' />
Amal Hashim
  • 28,306
  • 5
  • 31
  • 61
0

You can do it in one line of JavaScript without jQuery:

document.getElementById("pageTitle").innerHTML = String.format("{0:D}",new Date());

outputs: Wednesday, 07 October 2015 (date of StackOverflow post linked below)

String.format is provided by SharePoint

For more Date notations see: Changing date format using javascript

Danny '365CSI' Engelman
  • 21,176
  • 7
  • 35
  • 79