Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get date of 3 days ago

Tags:

sql

sql-server

I have SQL script that selects everything from current day.

SELECT  [ClientID] from [logs] where Date > CONVERT (date, SYSDATETIME())

Date is type of DateTime.

How to get everything within last 3 days? I suppose I need subtract 3 days from function SYSDATETIME() result, but how?

like image 997
vico Avatar asked Aug 06 '15 09:08

vico


People also ask

How to get 3 days back date in sql?

In my case: select * from Table where row > now() - INTERVAL 3 day; So you can fetch all of 3 days ago!

How do I get today's date in SQL?

To get the current date and time in SQL Server, use the GETDATE() function. This function returns a datetime data type; in other words, it contains both the date and the time, e.g. 2019-08-20 10:22:34 .

How do I subtract hours from a timestamp in SQL?

MySQL SUBTIME() Function The SUBTIME() function subtracts time from a time/datetime expression and then returns the new time/datetime.


1 Answers

SELECT  [ClientID] from [logs] where Date > DATEADD(day, -3, CONVERT (date, SYSDATETIME()))
like image 144
Backs Avatar answered Sep 21 '22 16:09

Backs