I have a Ticket_Date
column that is in the format YYYY-MM-DD HH:MI:SS
I want to check if the Ticket_date
is in the current month.
So far I have :
Ticket_date >= '2015-04-01' and Ticket_date < '2015-04-30'
but I need it to work with the current month rather then hardcoded
Advertisement
Answer
YEAR(Ticket_date) = YEAR(getdate()) and MONTH(Ticket_date) = MONTH(getdate())
but i would also save current date in variable to guarantee what result of getdate()
doesn’t change when executing long query at midnight
declare @today datetime = getdate() ... YEAR(Ticket_date) = YEAR(@today) and MONTH(Ticket_date) = MONTH(@today)