user3115933 user3115933 - 7 months ago 13
SQL Question

T-SQL syntax to filter records where the datetime variable is greater than or equal to the 1st Day of the Current Month

I am using SQL Server 2014 and I need to add a line of code to my SQL query that will filter the data extracted only to those records where the

StayDate
(a column in database) is
greater than or equal to
the
1st day of the current month
.

In other words, the line of code I need is the following:

WHERE StayDate >= '1st Day of Current Month'


Note:
StayDate
is in the
datetime
format (eg: 2015-12-18 00:00:00.000)

Answer

Use EOMONTH to get the first day of current month

WHERE  StayDate >= Dateadd(dd, 1, Eomonth(Getdate(), -1))