0

When I run a stored procedure in SQL Server 2008 CTP I get date "2012-10-31 00:00:00.000" with this format.

But when I am converting it using

Convert.ToString(drConversation["ConversationDate"])

in C#, I am getting "10/31/2012 12:00:00 AM".

Where should be problem? In C# code or in SQL Server?

4
  • 3
    Those values are identical; what is the problem? Commented Oct 31, 2012 at 13:49
  • You can easily call Convert.ToDateTime(drConversation["ConversationDate"]).ToString("yyyy-MM-dd HH:mm:ss.fff") in C# and get the exact same format as SQL Server returns - so what is the REAL problem here?? I don't see any issue.... Commented Oct 31, 2012 at 13:53
  • Data Masseur: When I am parsing string to Date time I have error. The error=> " DateTime represented by the string is not supported in calendar System.Globalization.GregorianCalendar." Commented Oct 31, 2012 at 13:53
  • Marc_s : DateTimeParseExcect(Convert.ToString(drConversation["ConversationDate"])) In function : I am returning DateTime.ParseExact(DateValue.Substring(0,10),DateExectParse, null); and My "DateExectParse" is format "dd/MM/yyyy". Commented Oct 31, 2012 at 13:54

3 Answers 3

1

There is no problem with it, The SQLServer use 24-hr format while the output from Convert class outputs 12-hr format.

Sign up to request clarification or add additional context in comments.

3 Comments

then why date format is change from"YYY-dd-mm" to "MM/dd/YYYY"?
because it is by default. do you want it to retain the format?
@chiragKhatsuriya you can use Convert.ToDateTime(drConversation["ConversationDate"]).ToString("yyyy-MM-dd HH:mm:ss.fff")
1

Actually it is the same date but in a different format.

If you would like to see it in the same format as in the Sql Server you can use:

DateTime.Parse(drConversation["ConversationDate"].ToString()).ToString("yyyy-MM-dd HH:mm:ss")

1 Comment

Why would you convert to string, then to Date, then back to string? ((Date) drConversation["ConversationDate"]).ToString("yyyy-MM-dd HH:mm:ss.fff") should do it right?
0

Try this way

DateTime mydate= Convert.ToDateTime(drConversation["ConversationDate"].ToString());

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.