How to create a Date in SQL Server given the Day, Month and Year as Integers

后端 未结 7 790
误落风尘
误落风尘 2020-12-05 12:22

FOR Example if I have:

DECLARE @Day int = 25
DECLARE @Month int  = 10 
DECLARE @Year int = 2016

I want to return

2016-10-2         


        
7条回答
  •  天涯浪人
    2020-12-05 13:08

    Old Microsoft Sql Sever (< 2012)

    RETURN dateadd(month, 12 * @year + @month - 22801, @day - 1)  
    

提交回复
热议问题