-1

Looking for some help regarding mysql date functions.

I am looking to show data for a time period of today to 8 days ago (I have been using this line of code in mysql WHERE TIME > CURDATE() - INTERVAL 8 DAY ) ) as well as the above time period but one year ago.

Cœur
  • 37,241
  • 25
  • 195
  • 267
KCh
  • 1
  • Possible duplicate of [MySQL get the date n days ago as a timestamp](https://stackoverflow.com/questions/1095831/mysql-get-the-date-n-days-ago-as-a-timestamp) – elki42 Jun 04 '18 at 17:18

1 Answers1

0

Try using DATE_SUB with TIMESTAMPDIFF,

TIMESTAMP syntax,

TIMESTAMPDIFF(unit, datetime_expr1, datetime_expr2);

DATE_SUB syntax,

DATE_SUB(date, INTERVAL value unit);

Example,

SELECT TIMESTAMPDIFF(SECOND, DATE_SUB('2018-06-04 22:59:00', INTERVAL 10 DAY), 
 '2018-06-04 22:59:00');
Roshana Pitigala
  • 8,437
  • 8
  • 49
  • 80