Created
March 22, 2022 12:02
-
-
Save josephwambura/a7b5ad414baab0135bdec43eb67dc692 to your computer and use it in GitHub Desktop.
Subtract two dates in Microsoft SQL Server
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In C#
SqlFunctions.DateDiff("day", c.CreatedDate, SqlFunctions.GetUtcDate()) > 180