src/openSourceC.DotNetLibrary.Core/Extensions/DateTimeExtensions.cs
/// <summary>
///		Gets a friendly date string in relation to todays date.
/// </summary>
/// <param name="obj">The <see cref="T:DateTime"/> object.</param>
/// <returns>
///		A friendly date string in relation to todays date.
/// </returns>
Gets a friendly date string in relation to todays date.
Gets a friendly date string in relation to todays date .
public static string ToFriendlyString(this DateTime obj)
		{
			DateTime today = DateTime.Today;
			int daysDiff = (int)today.Date.Subtract(obj.Date).TotalDays;
			DateTime lastYearCutoff = today.Date.AddYears(-1).AddDays(1);
			StringBuilder sb = new StringBuilder();
			if (daysDiff == 0)
			{
				sb.Append("Today");
			}
			else if (daysDiff == 1)
			{
				sb.Append("Yesterday");
			}
			else if (daysDiff < 6)
			{
				sb.Append(obj.DayOfWeek);
			}
			else if (obj >= lastYearCutoff)
			{
				sb.Append(obj.ToString("MMMM d"));
			}
			else
			{
				sb.Append(obj.ToString("MMMM d, yyyy"));
			}
			sb.AppendFormat(" at {0:hh:mm:ss tt}", obj);
			return sb.ToString();
		}
public static string ToFriendlyString ( this DateTime obj ) { DateTime today = DateTime . Today ; int daysDiff = ( int ) today . Date . Subtract ( obj . Date ) . TotalDays ; DateTime lastYearCutoff = today . Date . AddYears ( - 1 ) . AddDays ( 1 ) ; StringBuilder sb = new StringBuilder ( ) ; if ( daysDiff == 0 ) { sb . Append ( " " ) ; } else if ( daysDiff == 1 ) { sb . Append ( " " ) ; } else if ( daysDiff < 6 ) { sb . Append ( obj . DayOfWeek ) ; } else if ( obj >= lastYearCutoff ) { sb . Append ( obj . ToString ( " " ) ) ; } else { sb . Append ( obj . ToString ( " " ) ) ; } sb . AppendFormat ( " " , obj ) ; return sb . ToString ( ) ; }
Gets a friendly date string in relation to todays date.
Gets a friendly date string in relation to todays date .
A friendly date string in relation to todays date.
A friendly date string in relation to todays date .
DateTime
this
obj
None