locked
get date before three days ago RRS feed

  • Question

  • User-952877843 posted

    i have this table 

    id    date

    1      2010-08-26

    2      2010-08-24

    3      2010-08-23

    i want to that date column where date ago=3 in sql

    i wrote this code but not working fine

    SELECT  date from tb where date> DATEADD(day, -3 SYSDATETIME())

    Sunday, August 26, 2018 2:55 PM

Answers

  • User-1716253493 posted

    Use brackets for date word SELECT [Date] ...

    SELECT  [date] from tb where date < CAST(DATEADD(day, -3,GetDate()) as Date)

    GetDate() get current datetime

    CAST as Date to remove time part

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, August 27, 2018 1:22 AM
  • User-369506445 posted

    hi

    you can use DATEDIFF function for find different date between 2 fields ,  please try below query

    SELECT [date] from tb where  DATEDIFF(DAY,[date], getdate()) >= 3


     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, August 27, 2018 4:39 AM

All replies

  • User-474980206 posted

    you need to to get the date only:

    SELECT  date from tb 
    where date > DATEADD(day, -3, CONVERT(date, GETDATE()))



    Sunday, August 26, 2018 5:04 PM
  • User-1716253493 posted

    Use brackets for date word SELECT [Date] ...

    SELECT  [date] from tb where date < CAST(DATEADD(day, -3,GetDate()) as Date)

    GetDate() get current datetime

    CAST as Date to remove time part

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, August 27, 2018 1:22 AM
  • User-369506445 posted

    hi

    you can use DATEDIFF function for find different date between 2 fields ,  please try below query

    SELECT [date] from tb where  DATEDIFF(DAY,[date], getdate()) >= 3


     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, August 27, 2018 4:39 AM