Use BETWEEN in SQL Server

0

I need to show in the query the information that is not more than 120 days today so I think I could use BETWEEN but, I do not know how to use it in the correct way to know which day corresponds 120 days ago.

SELECT NOMBRE, PUESTO, FECHA
FROM EMPLEADOS
WHERE FECHA BETWEEN valor AND 2018-09-04
    
asked by ARR 04.09.2018 в 23:40
source

2 answers

3

Try this

DATEADD(DAY, -120, GETDATE())

More info link

    
answered by 04.09.2018 / 23:43
source
2

Try using this, I apply CONVERT to prevent it from filtering the time too:

SELECT NOMBRE, PUESTO, FECHA
FROM EMPLEADOS
WHERE FECHA 
BETWEEN CONVERT(DATE, DATEADD(DAY, -120, GETDATE())) 
AND     CONVERT(DATE, GETDATE());
    
answered by 05.09.2018 в 15:33