Instead of using string formatting strings, how about using the Day property
DateTime myDate = new DateTime(2009,6,4) int result = myDate.Day;
Or if you really need the result in string format
string result = myDate.Day.ToString();
If you want to get a specific date from a date object, rather than a formatted representation of the date, I prefer to use properties (Day, Month, Year, DayOfWeek, etc.). It makes reading the code a little easier (especially if someone else reads / supports it that doesn't remember the different formatting codes)
James Conigliaro Jun 12 '09 at 20:52 2009-06-12 20:52
source share