Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

i need to show date in "Time Ago" format?? how can i achieve this ?? we use XSLT to display announcements and here is XSLT code for date:

enter image description here

share|improve this question
    
There is no out of the box function to do that. You'd have to roll your own XSL template to evaluate the given date against the current date. It gets messy fairly quickly, with months having different numbers of days, leap years, etc. I have a template that is fairly accurate and only shows "xx days ago" and works fine over the year break period. If you're interested, I can post that. If you need something more complex like "2 Years, 5 months and 7 days ago", that would be a different story. –  teylyn Apr 21 '13 at 2:22
    
@Benny Skogberg: if possible post, i'll play with it to achieve my requirement –  Sachchin Annam Apr 21 '13 at 17:26
add comment

2 Answers 2

Try this formula, should print somehting like e.g X days X hours XX min :

=YEAR(Today)-YEAR(Created)-IF(OR(MONTH(Today)<MONTH(Created),AND(MONTH(Today)=MONTH(Created),DAY(Today)<DAY(Created))),1,0)&” years, “&MONTH(Today)-MONTH(Created)+IF(AND(MONTH(Today)<=MONTH(Created),DAY(Today)<DAY(Created)),11,IF(AND(MONTH(Today)<MONTH(Created),DAY(Today)>=DAY(Created)),12,IF(AND(MONTH(Today)>MONTH(Created),DAY(Today)<DAY(Created)),-1)))&” months,“&Today-DATE(YEAR(Today),MONTH(Today)-IF(DAY(Today)<DAY(Created),1,0),DAY(Created))&” days”

This is to be used in the Calculated Column, which you could then show as part of the output columns without manipulating XSLT.

share|improve this answer
add comment

Marc Anderson has a very handy XSL template for date calculations. Not sure if it does exactly what you are looking for but you can find out more and download from here.

share|improve this answer
add comment

Your Answer

 
discard

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.