Get Yesterday's Date

Often times, we want to analyze data with the date from yesterday. How do we auto-populate yesterday's date? There are a few formats that we can use!

 

The syntax below lets us get yesterday's date with timestamp:

select dateadd(day,-1,getdate()) 

To only get yesterday's date at 00:00:00: 

select dateadd(day,-1,trunc(getdate()))

If you wish to get the date and ditch the timestamp completely, you can use the SQL formatter!

select  [dateadd(day,-1,getdate()):date]

 

You can also use the interval syntax for a more elegant code:

select [getdate():date] - interval '1 day'

Reply Oldest first
  • Oldest first
  • Newest first
  • Active threads
  • Popular
Like Follow
  • 8 mths agoLast active
  • 1035Views
  • 1 Following