When we need to format dates as 1st Jul or 22nd Mar, we can use the following code.

  1. DateTime todayDate = DateTime.Now;
  2. DateTime dt = DateTime.Parse(todayDate.ToShortDateString(), CultureInfo.GetCultureInfo(“en-US”));  
  3. string month = dt.ToString(“MMM”, CultureInfo.GetCultureInfo(“en-US”));  
  4.   
  5. Calendar calendar = CultureInfo.InvariantCulture.Calendar;  
  6.   
  7. int dayOfMonth = calendar.GetDayOfMonth(showDate.ShowDate);  
  8. string suffix = string.Empty;  
  9. string formattedDay;  
  10.   
  11. switch (dayOfMonth)  
  12. {  
  13.     case 1:  
  14.     case 21:  
  15.     case 31: suffix = “st”break;  
  16.     case 2:  
  17.     case 22: suffix = “nd”break;  
  18.     case 3:  
  19.     case 23: suffix = “rd”break;  
  20.     default: suffix = “th”break;  
  21.  
  22. formattedDay = dayOfMonth.ToString() + suffix + “ ” + month;

Simple enough, huh? :) Oh.. one more thing I just wanna jot down. If we need more space for reading or inserting data in MS Office 2007, just hit Ctrl+F1 to hide the Ribbon. The key combination is a toggle key. Hitting them again will bring back Ribbon.

2 Comments

  1. Even better: just double-click any ribbon item to show/hide them. All the functionalities are still there when you click it and disappear when you’re done.
    Neat.

  2. Yep, I tried that, Chris. The way it works is more user-friendly.

    Thanks.

    TZ


Post a Comment

*
*