I am getting dates from database and i want to convert the date in dd/MM/yyyy format,
I am trying this but it gives me error "String was not recognized as a valid DateTime."
DateTime pDate = DateTime.ParseExact("05/28/2013 12:00:00 AM", "dd/MM/yyyy", CultureInfo.InvariantCulture);
Please let me know how i can convert into dd/MM/yyyy format?
Thanks
try with
MM/dd/yyyy hh:mm:ss tt
instead ofdd/MM/yyyy
if you use
DateTime.ParseExact
The format of the string representation must match a specified format exactly or an exception is thrown.if you need only the date
As per your comment, database contain data with Type 'Date', So you can read it directly as
DateTime
. You can convert to string by callingToString
with the expected Format.2 steps: