Jul 28, 2020 7:01 am
I want to write a SQL to get all people born between Yesterday and Today. Any help?
1 Reply
Jul 28, 2020 10:37 am
Hi, you can use the below query to get all people born between Yesterday and Today from the employee table.
Since it is a query related to Date function you can use DATEADD and then compare two dates.
Select Name, DateOfBirth, CAST(DateOfBirth as Date) as [DatePart]
From Employees
Where CAST(DateOfBirth as Date)
Between
DATEADD (Day,-1, CAST(GETDATE() as Date)) AND CAST(GETDATE() as Date)