Skip to content

Instantly share code, notes, and snippets.

@josephwambura
Created March 22, 2022 12:02
Show Gist options
  • Save josephwambura/a7b5ad414baab0135bdec43eb67dc692 to your computer and use it in GitHub Desktop.
Save josephwambura/a7b5ad414baab0135bdec43eb67dc692 to your computer and use it in GitHub Desktop.
Subtract two dates in Microsoft SQL Server
select CreatedDate , * from dbo_Customers
where
(DATEDIFF(day, CAST(CreatedDate as date), GETDATE())) > 180
-- day is for the intervals, could be minute, hour.
-- using 180 days (6 months) for testing.
-- The CreatedDate is of type DateTime (datetime2).
-- using Table dbo_Customers
@josephwambura
Copy link
Author

In C#

SqlFunctions.DateDiff("day", c.CreatedDate, SqlFunctions.GetUtcDate()) > 180

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment