Skip to content

Instantly share code, notes, and snippets.

@MarioBinder
Last active September 13, 2019 10:26
Show Gist options
  • Save MarioBinder/858385523492576f22cb to your computer and use it in GitHub Desktop.
Save MarioBinder/858385523492576f22cb to your computer and use it in GitHub Desktop.
select a daterange #sql #date
declare @selecteddate date = cast(getdate() as date);
SELECT *
FROM foo
WHERE Date >= DATEADD(day, 0, convert(date, @selecteddate)) and Date < DATEADD(day, 1, convert(date, @selecteddate))
Examples
declare @selecteddate date = cast(getdate() as date); --today
declare @selecteddate date = cast(getdate() -1 as date); --yesterday
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment