Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL datetime to C# string and back to SQL datetime

I have a webservice method that gets data from sql of the format 2012-11-18 11:21:03 when i save it to C# string it becomes this format: 18.11.2012 11:21:03 How do i change it back to the SQL format 2012-11-18 11:21:03 ?

like image 502
user1810659 Avatar asked May 08 '26 21:05

user1810659


1 Answers

Parse it into a dateTime again

DateTime myTime = DateTime.Parse(myString);

and back into a proper to string

myTime.ToString("yyyy-MM-dd HH:mm:ss");

Or just read it into a datetime and cut out the middleman.

like image 195
Haedrian Avatar answered May 11 '26 12:05

Haedrian



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!