I need to parse string value to date time value, I have date in this format:
DD.MM.YYYY
I want to parse value in this format:
YYYY-MM-DD
I tried to do it like this:
DateTime.ParseExact(date_req, "yyyy-MM-dd", CultureInfo.InvariantCulture);
But i have an error: String was not recognized as a valid DateTime.
Is there a way to do this?
I think what you want to do is parse your
dd.MM.yyyyand then display it asyyyy-MM-dd.You first have to parse the
stringinto aDateTime:Now
dateis a representation of the date that the computer actually understands (before it was just a string). You can now display this object anyway you want:Don’t forget that when converting dates from strings to
DateTimeand back, culture and time zones are worth keeping in mind.