When we need to format dates as 1st Jul or 22nd Mar, we can use the following code.
- DateTime todayDate = DateTime.Now;
- DateTime dt = DateTime.Parse(todayDate.ToShortDateString(), CultureInfo.GetCultureInfo(“en-US”));
- string month = dt.ToString(“MMM”, CultureInfo.GetCultureInfo(“en-US”));
- Calendar calendar = CultureInfo.InvariantCulture.Calendar;
- int dayOfMonth = calendar.GetDayOfMonth(showDate.ShowDate);
- string suffix = string.Empty;
- string formattedDay;
- switch (dayOfMonth)
- {
- case 1:
- case 21:
- case 31: suffix = “st”; break;
- case 2:
- case 22: suffix = “nd”; break;
- case 3:
- case 23: suffix = “rd”; break;
- default: suffix = “th”; break;
- }
- 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
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.
Yep, I tried that, Chris. The way it works is more user-friendly.
Thanks.
TZ