SQL Server Created Date

Can I create a date using SQL Server 2005?

Example, if I have year = 2010, month = 11 and day = 2, how can I convert or create it in datetime?

Below, if we write it in javascript

var date = new Date(2010, 10, 2, 0, 0, 0, 0);

and this is with oracle

SELECT TO_DATE('2010-11-02', 'YYYY-MM-DD') FROM DUAL

thank

+5
source share
6 answers

If you work with strings and want to convert to datetime data type, it is best to work with strings that can be uniquely converted to datetime. The following formats can be converted to datetime values ​​using SQL (either through CONVERT or without using SQL Server to convert) without any ambiguity:

'20101102'

'2010-11-02T10:59:59'

'2010-11-02T10:59:59.997'

4- , , . , (, '2010-11-02'), ( - , ODBC, - {d })

+3

SELECT {d '2010-11-02'}, ,

+3

. . msdn convert .

select convert(datetime, '2010-11-02', 120)
...
2010-11-02 00:00:00.000
+1

select convert(datetime, convert(char(8), 20101102))

0

You can use select convert(datetime, '11-11-2010')to convert to datetime.

0
source

You can just use set @datevar='20101102';. It is language independent and will be implicitly converted.

0
source

All Articles