This utility will help you to format date in very user friendly format. It is not formatting date in exact different format while it translate the in day name as well as yesterday and today format.
public static string Get_Friendly_Date(System.DateTime src)
{
System.DateTime currentdate = DateTime.Now;
int datediff = (src - currentdate ).Days;
if (datediff == -1)
{
return "Yesterday";
}
else if (-7 <= datediff && datediff <= -2)
{
return "Last " + src.DayOfWeek.ToString();
}
else if (datediff == 0)
{
return "Today";
}
else if (1 <= datediff && datediff <= 7)
{
return "This " + src.DayOfWeek.ToString();
}
else
{
return src.ToString();
}
}
Check out this library:
ReplyDeletehttp://plugins.jquery.com/project/fIsForFormat
It is the most useful thing I’ve found when it comes to Date formatting in JavaScript. Not only does it make formatting a piece of cake, but it has many other cool features as well!
I use these two scripts in my webapps and they work great together!! I'm able to manipulate dates as needed on the fron-end and back-end on the fly!