7
Answers

Date Time conversion

Hi ,

I am converting MM/dd/yyyy date to yyyy-MM-dd hh:mm:ss using dateobject.ToString("yyyy-MM-dd hh:mm:ss").

Its converting perfectly in given format but in MM-dd-yyyy format there is no hour specified and hour is appearing in this yyyy-MM-dd hh:mm:ss format .

For e.g.  date is 05/07/2009   i.e. 7 May 2009 and after converting to yyyy-MM-dd hh:mm:ss format, date is appearing as 2009-05-07 12:00:00.

From where this 12 is appearing ? We don't want this 12 . The date should display like  2009-05-07 00:00:00.

Please suggest solution.

Thanks
Prasad

Answers (7)
0
Jiteendra Sampathirao

Jiteendra Sampathirao

NA 6.9k 1.5m 13y


Hi,
Go through these links:

http://www.sql-server-helper.com/tips/date-formats.aspx
http://msdn.microsoft.com/en-us/library/az4se3k1.aspx

0
Jiteendra Sampathirao

Jiteendra Sampathirao

NA 6.9k 1.5m 13y

Hi,

Do like this::

string @DOB = DateTime.ParseExact(txtDOB.Text, "dd/MM/yyyy",  System.Globalization.CultureInfo.CurrentUICulture. DateTimeFormat).ToString("MM/dd/yyyy");



Otherwise post the code here...
0
Abhimanyu K Vatsa

Abhimanyu K Vatsa

NA 50.9k 12.4m 13y
if you still find problem then provide us the code you are using, will try to find out the mistake. 

thanks
0
Prasad Godbole

Prasad Godbole

NA 153 141.7k 13y
Hi all,


Thanks for giving solutions.

I used 24 hours date format and now hour is appearing 00.


Thanks again

Kind Regards
Prasad
0
Abhimanyu K Vatsa

Abhimanyu K Vatsa

NA 50.9k 12.4m 13y
read this msdn post, it probably will help you.

http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx
0
Vulpes

Vulpes

NA 98.3k 1.5m 13y
It's just struck me that the problem here is that you're using the 12 hour clock ("hh" format). If you change to the 24 hour format ("HH"), then it should get rid of the 12:00:00  i.e. dateobject.ToString("yyyy-MM-dd HH:mm:ss").
0
Vulpes

Vulpes

NA 98.3k 1.5m 13y
See if using dateobject.Date.ToString("yyyy-MM-dd hh:mm:ss") gets rid of the hour.