SELECT all records that are 30 days old

后端 未结 4 717
盖世英雄少女心
盖世英雄少女心 2020-12-11 22:57

I need to SELECT all records that are 30 days old. I have the code below but it\'s not working. In updatestatus I have dates like 12/26/2011. I create a 30 day old date like

4条回答
  •  旧时难觅i
    2020-12-11 23:19

    You can try this way. In SQL, there is dateadd function and I think there should be similar function in MySQL.

    select *
    from Table
    where str_to_date between dateadd(day,-30,getdate()) and getdate()
    

    It retrieve records between current date and past 30 days. You need to adjust for time. If you don't count time, you need to remove timestamp.

提交回复
热议问题