SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've noticed that SharePoint 2013 uses past tense time periods for a lot of it's date formatting. eg

  • A few seconds ago
  • Yesterday at 3:00pm
  • 5 days ago etc.

Is there a JavaScript method available that takes a date and returns that type of format?

share|improve this question

When I worked with ClientContext I got dates in form of Date.
You could use any library that works on that, such as .

var c = new SP.ClientContext();
var w = c.get_web();
c.executeQueryAsync(function() {
    var created = moment(w.get_created()).fromNow();
    // "6 months ago"
share|improve this answer
I had originally deleted this post because I realized it does not correctly answer @paul-lucas question. But it might still be interesting to see how to get dates the other way around, as well as considering fetching dates through ClientContext when they are hard to parse. Moments does not support parsing of 'Timeago' – eirikb Sep 11 '12 at 8:33

I haven't seen this javascript code in sharepoint javascript API. I would like to recommend moment.js a lightweight javascript library for date and time handling in javascript which can show relative time as well

share|improve this answer

Not in 2010 and haven't found one in 2013 (yet). The method SP uses to generate the formatting is SPUtility.TimeDeltaAsString(). I've Reflector in that method in 2010 and it seems to be fairly straight forward if I was to do a JavaScript implementation. Maybe the same approach would work in 2013?

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.