Date serial in SQL?

前端 未结 2 936
梦如初夏
梦如初夏 2020-12-03 11:12

How can I convert a day [1-31] and a month [1-12] and a year (all int), to a date serial IN SQL (without converting to varchar)?

2条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-03 12:00

    A few functions have been added in SQL Server 2012 which will allow you to do this with DATEFROMPARTS, DATETIMEFROMPARTS and TIMEFROMPARTS amongst others.

    Example:

    SELECT DATEFROMPARTS(2018,2,1) -- returns 2018-02-01
    

提交回复
热议问题