Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

convert date string to datetime

Tags:

c#

datetime

I have date string in format dd-MMM-yyyy and want to convert this to datetime, when I use below code

DateTime.ParseExact("20-Oct-2012", "yyyy-MM-dd HH:mm tt", null) 

it causing an error

String was not recognized as a valid DateTime.

When I modify above code

DateTime.ParseExact("20-Oct-2012", "dd-MMM-yyyy", null) 

then I got date time in format (mm/dd/yyyy) : 10/20/2012 12:00:00 AM

But I need it should be converted in yyyy/mm/dd format. Please help me in this regard.

like image 262
Vinod Chakote Avatar asked Dec 10 '25 14:12

Vinod Chakote


1 Answers

You should try this

DateTime.ParseExact("20-Oct-2012", "dd-MMM-yyyy", null).ToString("yyyy/mm/dd")

For further reading on formats Check This

like image 58
Arjun Shetty Avatar answered Dec 13 '25 05:12

Arjun Shetty



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!