Say that the current date is March 1, 2010, I want to display it like this ...
20100301 as the first 4 digits = year, 2 digits = month, 2 digits = day
is there an easy way to do this?
use format
yourdatetimeObj.ToString("yyyyMMdd");
Link: http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx
Sort of
dateTimeObject.ToString("yyyyMMdd");
See String Format for DateTime
var mydate = DateTime.Now; // Whatever you want. mydate.ToString("yyyyMMdd");
DateTimeFormatInfo , .
ToString() DateTime, , , , , :
var now = DateTime.Now; var msg = String.Format("Now: {0:dd/MM/yyyy}", now);
Console.Write("Now: {0:MM/dd/yyyy}", now);