Show last updated date in Blogger posts

 Posted by:   Posted on:   Updated on:  2018-06-23T17:32:11Z

How to get and display last updated date of Blogger posts using a script that reads the blog feed.

Although this is not the kind of post for this blog, I decided to write about this because there are opinions saying it is impossible to show updated date in Blogger posts. Blogger offers support only for the date when a post is published. You can, of course, edit the post and change published date, but that is not what most people want.
The method that follows is completely automatic and it will print the last date when you used the post editor on the specific post. It makes use of data stored in blog feed, because, although there is no tag for updated date in Blogger (something similar to published date tag data:post.timestamp), the updated date is stored in your blog feed. I first noticed this when I registered my blog on Tapatalk and noticed that updated posts appeared on top of the list.
Show last updated date in Blogger posts

New method

In order to be compliant to structured data tags format, Blogger actually provides a way to get the that a post was updated. The tag is data:post.lastUpdatedISO8601, but I can't find its documentation at official Blogger documentation page. It seems this tag has been around 2015. It doesn't require you to use jQuery or to have the blog feed enabled.

There is no way to change date format. So, you still have to use a script to format the ISO8601 date. Here is an example.
<span class='updated' expr:title='"Post was updated on " + data:post.lastUpdatedISO8601' id='updatedateinfo' itemprop='dateModified'>
    <data:post.lastupdatedISO8601/>
  </span>
  <script>
    var dates = "<data:post.lastUpdatedISO8601/>"
    var dateu = new Date(dates);
    var months = ["January","February","March","April","May","June","July","August","September","October","November","December"];
    document.getElementById("updatedateinfo").innerHTML = months[dateu.getMonth()] + " " + dateu.getDate() + ", " + dateu.getFullYear();
  </script>
That's all you have to do. The old method is still published below.

Prerequisites

Of course, you must have a Blogger blog. You must enable the feed by going to Settings, Other, Site Feed. I'm using Until Jump break setting, but I guess everything will work except None. Your blog must also use jQuery. Somewhere in your template you should have in the head section (or add if there isn't) the line:
<script src='https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js' type='text/javascript'/>
It's OK to use a different jQuery version.

The script

Here is the script originally written by Yu-Jie Lin that will fetch the feed as JSON, parse it, get the date and display it.
<b>Updated on:</b> <span id='updatedateinfo'>-</span>

<script>
var postID = "<data:post.id/>";
jQuery.getJSON('https://www.blogger.com/feeds/replace_with_blog_id/posts/summary/' + postID + '?alt=json-in-script&callback=?', function(data) {
    var entry = data.entry;
    var dateu = new Date(entry.updated.$t);
    var months = ["January","February","March","April","May","June","July","August","September","October","November","December"];
  document.getElementById("updatedateinfo").innerHTML = months[dateu.getMonth()] + " " + dateu.getDate() + ", " + dateu.getFullYear();
  document.getElementById("updatedateinfo").title = dateu;
}); 
</script>
The script will show the date inside a span element with id=updatedateinfo. Don't forget to adjust the URL with the correct blog ID.
You can improve it if you want. For example, you can compare published date with updated date and display updated date only if it is different.
This method has one big disadvantage. You can't use structured data tags for the span element (i.e. itemprop=dateModified) because search engines will not run the Javascript code and will not index updated date.

9 comments :

  1. Where do I paste the set of code?

    ReplyDelete
    Replies
    1. Where in the page you want the updated date to appear. In the theme HTML editor.

      Delete
  2. I can't find the tag for the post timestamp. Where do I find it? My blog is http://aruskemodenan.blogspot.com.

    ReplyDelete
  3. This comment has been removed by a blog administrator.

    ReplyDelete
  4. Hi, is it possible to change format date to DD-MM-YY? and change months name in other language? I tried to change July to Luglio in italian but obtain undefined NaN, NaN

    thanks

    ReplyDelete
    Replies
    1. Current Blogger tags can only provide ISO8601 format for updated date. With Javascript code, this format can be changed to anything, but I don't have enough Javascript knowledge to be able to do it.

      Delete
  5. I get the following error : The reference to entity "callback" must end with the ';' delimiter.

    ReplyDelete
    Replies
    1. There is no callback in this code. The error is somewhere else.

      Delete

Please read the comments policy before publishing your comment.