1

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?

2
  • 1
    order date is a unix timestamp, and reorder is a day number, aren't they? Commented May 30, 2012 at 13:03
  • 1
    SELECT * FROM table_name WHERE UNIX_TIMESTAMP() >= (order_time_col + (reorder_days_col * 86400)) Commented May 30, 2012 at 13:04

3 Answers 3

2
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...

Sign up to request clarification or add additional context in comments.

4 Comments

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)
The query is also comparing the seconds and it doesn't obviously doesn't match; Update coming.
@Sebas I don't have a MYSQL engine - Allow me to introduce you to SQLFiddle ;-)
that was not your question ;) "order date = date + reorder"
0

timestamp is number of seconds passed from 1st Jan 1970 so in order convert timestamp value to days one needs to multiply it with 60 * 60 * 24 (= 86400)

Comments

0

Something like this should work:

SELECT * FROM orders WHERE `date` < UNIX_TIMESTAMP() - reorder*86400; # returns all orders, `date` field of which is older than 90 days ago

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.