Display the File Last Updated Date Using jQuery in SharePoint

In this example, assume there is a dashboard page on a SharePoint site that displays a number of graphs and charts. This dashboard is based on data contained in a single file located in a document library on the same site. Whenever this file is updated, the last modified date of the file needs to be automatically reflected on the dashboard page. This allows the page viewer to know the freshness of the dashboard data without requiring the content owner to edit the dashboard page itself with every data change. The following code will display the file last updated date using jQuery, the SharePoint Client Object Model (sp.js), and a bit of HTML. The formatDate function is used to format the file last modified timestamp in dd-mon-yyyy format.

Add a Content Editor Web Part to the dashboard page and include the following script in the source (or as a reference to a script file).

Change the FileUrl variable in getFileInfo() to the appropriate file path. When the code executes, it will replace the contents of the “data_last_update_date” container with the formatted last modified timestamp.

<script src="http://code.jquery.com/jquery-latest.min.js"></script>

<script type="text/javascript">
  function getFileInfo() {
    var clientContext = SP.ClientContext.get_current();
    var web = clientContext.get_web();
    var FileUrl = '/path/to/file.txt';
    var file = web.getFileByServerRelativeUrl(FileUrl);


      function() {
        $('#data_last_update_date').html("Data Last Updated: " + formatDate(file.get_timeLastModified()));
      function(sender, args) {
        console.log('Function getFileInfo() failed: ' + args.get_message());

  function formatDate(timestamp) {
    var month_names = new Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
    var pad = "00";

    if(timestamp) {
      var d = new Date(timestamp);

      return (pad + d.getDate()).slice(-pad.length) + "-" + month_names[d.getMonth()] + "-" + d.getFullYear();

  $(document).ready(function() {
    ExecuteOrDelayUntilScriptLoaded(getFileInfo, "sp.js");

<p> </p>
<div id='data_last_update_date' style='text-align:center; width:100%;'></div>

5 thoughts on “Display the File Last Updated Date Using jQuery in SharePoint”

  1. Hi John – Your use case describes my needs…exactly. I followed the instructions to the ‘t’, but the container is empty. I’m using SP 2013. Any ideas?

  2. Hi John, great script you’ve developer here, I would like to use it multiple times on a SharePoint site Wiki page, but it only works for one file, I have a matrix of 8 files where I want to show last updated data for each of them on one page, changing the div ID doesn’t work, can you help me fix this issue?


Leave a Comment