0

I have a table named pro_time where the time values are stored in epoch dates. I want to select every row where pro_time value difference between the current date is more than seven days. I have a relatively long query and I wish to solve this with as minimal code as possible. What is the best way to do this?

liaf
  • 1
  • MySQL does not know what "epoch dates" is. Maybe you mean TIMESTAMP? – Akina Jun 18 '20 at 12:50
  • I am! My values are like '1592482521' – liaf Jun 18 '20 at 12:52
  • This is TIMESTAMP in MySQL terms. Use [DATEDIFF() function](https://dev.mysql.com/doc/refman/8.0/en/date-and-time-functions.html#function_datediff). Or TIMESTAMPDIFF(DAY, ...). – Akina Jun 18 '20 at 12:58
  • Does this answer your question? [How to get the number of days of difference between two dates on mysql?](https://stackoverflow.com/questions/2490173/how-to-get-the-number-of-days-of-difference-between-two-dates-on-mysql) You can use NOW() for one of the parameters. – thelr Jun 18 '20 at 13:02
  • I am trying this right now: `DATEDIFF(UNIX_TIMESTAMP() -`pro_time`) >= 7` but it comes back with #1582 - Incorrect parameter count in the call to native function 'DATEDIFF' – liaf Jun 18 '20 at 13:17
  • (UNIX_TIMESTAMP(NOW()) -`pro_time`) <= 7 runs well but the result is not correct. I should have one result when I see the difference between current time and the stored time but the query comes back with zero results. – liaf Jun 18 '20 at 13:26

0 Answers0