SQL Server datetime datatype does not allow many formats

I have a table in SQL Server 2005 that has a date field. I want to save the date time value in a format mm/dd/yyyy hh:mm:ss, but I think SQL Server allows date time in a format yyyy-mm-dd HH:mm:ss.ll.

I can save the date value in a format mm/dd/yyyy hh:mm:sslike varchar, but this defeats my intention to sort the table into a date date field.

Is there anything in my approach? Any suggestions?

amuses

+3
source share
4 answers

The datetime type does not store it in yyyy-mm-dd HH:mm:ss.ll, as you say.

Datetime 8- . yyyy-mm-dd HH:mm:ss.ll - , . , CONVERT.

+7

-, :

convert(varchar, [datefield], style) 

, . .

, .

+2

; , , .

""? , , SQL Server Management Studio.

, , ( .).

0
source

I must admit that I never tried to force the database to save any particular date / time format. I think this is really not necessary.

So, do you have a date / time field and can you sort your data? This is about as much as you need from a DBMS. Perform final formatting at the presentation level of your application.

0
source

Source: https://habr.com/ru/post/1708776/


All Articles