SQL Server date comparisons based on month and year only

后端 未结 6 1014
南方客
南方客 2021-02-05 06:27

I am having trouble determining the best way to compare dates in SQL based on month and year only.

We do calculations based on dates and since billing occurs on a monthl

6条回答
  •  甜味超标
    2021-02-05 07:09

    You can filter the month and year of a given date to the current date like so:

    SELECT * 
    FROM tableName 
    WHERE month(date2) = month(getdate()) and year(date2) = year(getdate())
    

    Just replace the GETDATE() method with your desired date.

提交回复
热议问题