user3115933 user3115933 - 1 year ago 91
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

(a column in database) is
greater than or equal to
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'

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

Answer Source

Use EOMONTH to get the first day of current month

WHERE  StayDate >= Dateadd(dd, 1, Eomonth(Getdate(), -1)) 
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download