简体   繁体   中英

Date format for SQL Server 2008 R2

I have an Event table with a column called start_date of datatype DateTime . From C# application date is showing up like 07/12/2011 and when saved in table its like 2011-08-12 11:00:00.000 .

How can I make this format of date be saved like 2011-12-08 11:00:00.000 instead of above?

I am not using a stored procedure/function in SQL Server, instead I'm using Entity Framework. I want that date auto formatted and saved like above.

anyone please.

Dates are not stored in SQL Server as a string. That's just how Management Studio or whatever application you're using to view the data in the tables is presenting it. Usually the order of year-month-day is determined by the language and culture settings.

I think you can use SET DATEFORMAT to mess with the defaults if you so desire, but it won't change how the dates are actually stored just how they are presented and/or parsed.

The datetime in SQL Server isn't stored in any string-based format - it's stored as a numerical 8-byte value.

The string representation you see is the default representation defined by your language/regional settings, and the date format setting in SQL Server.

You can't as far as I'm aware. Also, if you are using SQL Server 2008, consider the date , time , and datetime2 data types. The datetime and shortdatetime data types are mainly there for backwards compatibility.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM