Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get days from current timestamp in SQL query

Tags:

sql-server

I have a table:

ID      Timestamp
1       2010-07-27 13:14:00.000
2       2010-08-13 13:14:00.000
3       2010-12-21 13:14:00.000

Now I need to subtract the day from Timestamp column with current getdate() and get the days from it.

like image 427
happysmile Avatar asked Aug 31 '26 13:08

happysmile


1 Answers

You can use DATEDIFF

SELECT DATEDIFF(day, Timestamp, getdate())
FROM   YourTable

DATEDIFF

Returns the count (signed integer) of the specified datepart boundaries crossed between the specified startdate and enddate.

Syntax

DATEDIFF ( datepart , startdate , enddate )
like image 140
Lieven Keersmaekers Avatar answered Sep 03 '26 07:09

Lieven Keersmaekers



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!