I have table with orders list. Each order have order date (timestamp 1331182800). For each order user can select automatic reorder by 30, 60 or 90 days (reorder field (int)).
I need sql for cron to select all orders, that have order date = date + reorder. (date order + 30 or 60 or 90 days).
Can You help me with this?
3 Answers
SELECT * FROM orders o WHERE DATE_FORMAT(DATE_SUB(NOW(), INTERVAL o.reorder DAY), '%d/%m/%Y') = DATE_FORMAT(FROM_UNIXTIME(o.date), '%d/%m/%Y')
edited to skip the seconds from the comparison. I don't have a MYSQL engine so some errors still could occur, if that was so I'm sorry about such inconvenient...
4 Comments
YamahaSY
its returns me empty result. i have an order with order date 28 may 2012 (1338183074) in reorder field i put 2 My query is: SELECT * FROM orders WHERE date_add(NOW(), INTERVAL reorder DAY) = FROM_UNIXTIME(
ord_date)Sebas
The query is also comparing the seconds and it doesn't obviously doesn't match; Update coming.
DaveRandom
@Sebas
I don't have a MYSQL engine - Allow me to introduce you to SQLFiddle ;-)Sebas
that was not your question ;) "order date = date + reorder"
SELECT * FROM table_name WHERE UNIX_TIMESTAMP() >= (order_time_col + (reorder_days_col * 86400))