Reputation: 33
I'm trying to figure out a way to take a date in a table in SQL, check if it's older than the value in another column and possibly output the difference.
For Example:
ColA has a standard SQL date stamp of 2011-12-12 04:10:00.000 ColB has a number in it such as 10 I'd like to be able to compare todays date to the date in (ColA + the value in ColB)
ColB's values are in days so adding the 10 above would mean ColA's date + 10 would be: 2011-12-22 04:10:00.000.
I'm trying to figure out how to compare todays date with this date to see if how many days from today it is. In this case (12-22-2011) it would be 45 days ago.
Hopefully this explanation isn't too confusing.
Upvotes: 2
Views: 124
Reputation: 300559
Use DATEDIFF
and DATEADD
to manipulate and compare SQL Server dates/datetimes.
e.g
DATEADD(day, 10, ColA)
and
IF DATEDIFF(day, DATEADD(day, 10, ColA), GETDATE()) > SomeNumberofDays
Upvotes: 3