How can I convert a datetime object to the format yyyy/MM/dd? I am trying this:
DateTime selectedDate =Convert.ToDateTime( Calendar1.SelectedDate.ToShortDateString());
selectedDate = DateTime.ParseExact(selectedDate, "yyyy/MM/dd", CultureInfo.InvariantCulture);
But I get the following errors:
The best overloaded method match for ‘System.DateTime.ParseExact(string, string, System.IFormatProvider)’ has some invalid arguments
or
Argument ‘1’: cannot convert from ‘System.DateTime’ to ‘string’
A
DateTimedoes not have an inherent format – only an internal representation.Formatting comes into play when you want to display the value of the
DateTimeinstance:The above
formattedstring will contain the values of theDateTimeinstance in the required format.