SQL Server Date Format Function

SELECT CONVERT(VARCHAR(10), GETDATE(), 105)  

This query returns the date in the field [DD-MM-YYYY] format as varchar. I need the same format in datetime datatype on sql server. Pls help me

+3
source share
3 answers

In SQL Server, the DATETIME data type is stored as 2 4-byte integers, so they don’t have a specific formatting like this.

If you want to return the date in a specific format, you need to convert it to VARCHAR with the specified corresponding format identifier.

datetime VARCHAR DATETIME SQL Server, , SQL , . dd/mm/YYYY , mm/dd/yyyy, . :

yyyyMMdd
yyyy-MM-ddThh:mi:ss.mmm

.

INSERT MyTable (DateField) VALUES ('01/10/2010') -- dd/MM/yyyy not safe
INSERT MyTable (DateField) VALUES ('20101001') -- yyyyMMdd safe

Update:
DATETIME (GETDATE(), , ...), , SSMS, , , , , 8 .

+3

,

SELECT CONVERT(DATETIME, GETDATE(), 105)

VARCHAR DATETIME

0

This will return datetime

SELECT GETDATE()
0
source

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


All Articles