Forum

How to Write a SQL ...
 
Notifications
Clear all

How to Write a SQL Query to get all people born between Yesterday and Today


Pavan NJ
Posts: 47
 Pavan NJ
Topic starter
(@Pavan NJ)
Joined: 1 year ago

I want to write a SQL to get all people born between Yesterday and Today. Any help?

1 Reply
Sandeep0069
Posts: 36
 Sandeep0069
(@Sandeep0069)
Joined: 1 year ago

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)
Reply
Share: