How do I convert a DateTime object to YYMMDD format?
Another alternative that you can do this is by:
var formattedDate = string.Format("{0:yyMMdd}", DateTime.Now);
Hope this helps!
The reference for the format string is at MSDN: Custom DateTime Format Specifiers.
What you are looking for specifically is:
yy Represents the year as a two-digit number. If the year has more than two digits, only the two low-order digits appear in the result. If the year has fewer than two digits, the number is padded with leading zeroes to achieve two digits.
MM Represents the month as a number from 01 through 12. A single-digit month is formatted with a leading zero.
dd Represents the day of the month as a number from 01 through 31. A single-digit day is formatted with a leading zero.
DateTime.Now.ToString("yyMMdd")
You may also find the following two posts on MSDN useful as they contain a lot of info about DateTime formatting:
Standard Date and Time Format Strings
Custom Date and Time Format Strings