Forum

How to Write a SQL ...
 
Share:
Notifications
Clear all

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

2 Posts
1 Users
0 Likes
291 Views
Pavan NJ
Posts: 47
 Pavan NJ
Guest
Topic starter
(@Pavan NJ)
Eminent Member
Joined: 2 years ago

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

1 Reply
Sandeep0069
Posts: 36
 Sandeep0069
Guest
(@Sandeep0069)
Eminent Member
Joined: 2 years 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

Leave a reply

Author Name

Author Email

Title *

 
Preview 0 Revisions Saved
Share: