I am trying to update certain fields for employees whose date of joining falls in between 10 Jun and 31 Dec, irrespective of the year. I am trying using ‘Between’ Operator but it requires year to be included in the dates. Is there a way to generalise it in order to consider Day and Month excluding the Year?
Advertisement
Answer
Use the DatePart function – replace thedate with your column, and thetable with the column.
Something like this:
select datepart(MONTH, thedate), datepart(DAY, thedate),* from thetable where datepart(MONTH, thedate) between 6 and 12 and datepart(DAY, thedate) between 10 and 31