DateTime query on only year in SQL Server

前端 未结 8 1614
灰色年华
灰色年华 2021-01-12 08:01

I want to select multiple records on the basis of a matching year, for example in table tab where columns are [id] int, [name] varchar, [boo

8条回答
  •  醉梦人生
    2021-01-12 08:29

    One of the most important things to remember with regards to SQL Server and dates is that the best format to use is this: 'YYYYMMDD' (or 'YYYYMMDD HH:MI:SS'). This format will always be interpreted properly by SQL Server, regardless of regional date settings.

    SELECT [ACCNO] 
          ,[Roll No] 
          ,[IssueDate] 
          ,[DueDate] 
      FROM [test1].[dbo].[IssueHis$]  
     WHERE [IssueDate] >= '20090101' 
       AND [IssueDate] < '20100101'
    

提交回复
热议问题