Click here to Skip to main content
15,897,519 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
<%#System.DateTime.Now.Subtract(Convert.ToDateTime(Eval("Date")))%>

This code show result like this:
00:22:27.3738750
it means 22 minutes 27 sec ago but i want it show only 22 minutes ago.and it also not display the minutes and hours after the result. Please help me how to get it.

Thanks in advance
Posted
Comments
Sergey Alexandrovich Kryukov 21-May-11 23:45pm    
You should not re-post. You previous question is nearly identical to this one.
--SA

1 solution

Something like this should work

<%# System.DateTime.Now.Subtract(Convert.ToDateTime(Eval("Date"))).Minutes + " minutes ago" %> 


Else have a public function, say,

public string GetInfo(object date)
{
   return DateTime.Now.Subtract(Convert.ToDateTime(date.ToString())).Minutes + " minutes ago";
}


and then use it as

<%# GetInfo(Eval("Date")) %>


Hope this helps!
 
Share this answer
 
v2
Comments
rahul dev123 21-May-11 7:13am    
No it shown a wrong result. 1hr 26mint ago but it shown only 26 mint ago
Karthik. A 21-May-11 9:43am    
Check out this link - http://msdn.microsoft.com/en-us/library/system.datetime.aspx
You will have to use a TimeSpan object and calculate total seconds

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900