Junior
Dates
SQL & Databases
Write a query to find employees hired in the last 30 days.
Short answer: Filter HireDate >= DATEADD(DAY, -30, CAST(GETDATE() AS date)). Prefer sargable predicates — avoid wrapping the column in functions when possible.
Sample solution
T-SQL
SELECT EmpId, Name, HireDate FROM Employees WHERE HireDate >= DATEADD(DAY, -30, CAST(SYSUTCDATETIME() AS date));
Mention SYSUTCDATETIME vs GETDATE and time-zone awareness for global apps.
Share this Q&A
Share preview image: https://www.toolliyo.com/images/toolliyo-logo.png