days ago date format

how do i show this date format on a repeater?

 function formatDaysAgo(date) { var ago = new Date().getTime() - date.getTime(); 

  if (ago < 44 * 1000) 
 return "a few seconds ago"; 
 else if (ago < 89 * 1000)
  return "a minute ago"; 
  else if (ago < 44 * 60 * 1000) 
  return Math.round(ago / 60 / 1000) + ' minutes ago';
   else if (ago < 89 * 60 * 1000) 
   return "an hour ago"; 
   else if (ago < 21 * 60 * 60 * 1000) 
   return Math.round(ago / 60 / 60 / 1000) + ' hours ago'; 
   else if (ago < 35 * 60 * 60 * 1000)
    return "a day ago"; 
    else if (ago < 25 * 24 * 60 * 60 * 1000) 
    return Math.round(ago / 24 / 60 / 60 / 1000) + ' days ago'; 
    else if (ago < 45 * 24 * 60 * 60 * 1000) 
    return 'a month ago'; else if (ago < 319 * 24 * 60 * 60 * 1000) 
    return Math.round(ago / 29 / 24 / 60 / 60 / 1000) + ' months ago'; 
    else if (ago < 547 * 24 * 60 * 60 * 1000) 
    return 'a year ago'; 
    else 
    return Math.round(ago / 365 / 24 / 60 / 60 / 1000) + ' years ago'; } 
    

You will need to set the appropriate repeater field in the Repeater.onItemReady() function.

Good luck,

Yisrael

Hi!
I’m trying to implement this but the instructions are insufficient; could someone please help me?

Clearly this what I did is not right:

I have a repeater that is connected to my blog’s database, and in the repeater I have a text that is connected to the publishedDate field of my blog database. I want that date to be in a form of " x time ago" as shown in this thread…

A million thanks in advance if someone could help me out with this!