Creating date in SQL Server 2008

前端 未结 3 1948
天命终不由人
天命终不由人 2021-02-07 01:23

Is there something similar to DATEFROMPARTS(year, month, day) in SQL Server 2008? I want to create a date using the current year and month, but my own day of the mo

3条回答
  •  青春惊慌失措
    2021-02-07 01:50

    You could use something like this to make your own datetime:

    DECLARE @year INT = 2012
    DECLARE @month INT = 12
    DECLARE @day INT = 25
    
    SELECT CAST(CONVERT(VARCHAR, @year) + '-' + CONVERT(VARCHAR, @month) + '-' + CONVERT(VARCHAR, @day)
     AS DATETIME)
    

提交回复
热议问题