MySQL get the date n days ago as a timestamp

前端 未结 3 1563
萌比男神i
萌比男神i 2020-12-13 03:18

In MySQL, how would I get a timestamp from, say 30 days ago?

Something like:

select now() - 30

The result should return a timestamp

3条回答
  •  感动是毒
    2020-12-13 04:02

    You could use:

    SELECT unix_timestamp(now()) - unix_timestamp(maketime(_,_,_));
    

    For unix timestamps or:

    SELECT addtime(now(),maketime(_,_,_));
    

    For the standard MySQL date format.

提交回复
热议问题