Forum

Can anyone tell me ...
 
Notifications
Clear all

Can anyone tell me How to Write a SQL Query to get all people born on Yesterday?


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

How to achieve this SQL Query to get all people born on Yesterday

1 Reply
Sandeep0069
Posts: 36
 Sandeep0069
(@Sandeep0069)
Joined: 1 year ago
 
Let us do some workaround to achieve this.
   
Select (GETDATE)   Will give us the current Date with the timestamp
 
      To Avoid timestamp we can use CAST Function
 
        Select CAST(GETDATE() as Date) will give us the date without a timestamp. 
 
  
  Final Query Query
 
        Select DATEADD(Day,-1,CAST(GETDATE() as Date)) as [Datepart]
   
                From Employees
 
                     Where CAST(DateOfBirth as Date) = DateADD(Day,-1, CAST(GETDATE() as DATE)
Reply
Share: