I have “Employee” table with employees’ “StartDate”.
I want to get a list of all employees who are reaching their work anniversary next month.
So far I have reached up to this point:
SELECT * FROM Employee WHERE DATEDIFF(DAY, DAY(StartDate), DAY(GETDATE())) = 30
…but this doesn’t seem to be working.
Advertisement
Answer
I want to get a list of all employees who are reaching their work anniversary next month.
first you find the next month date
DATEADD(MONTH, 1, GETDATE())
then you find the Employee whose StartDate
is next month
SELECT * FROM Employee WHERE DATEPART(MONTH, StartDate) = DATEPART(MONTH, DATEADD(MONTH, 1, GETDATE()))