Page 1 of 1

SELECT NOW() - 2 days

Posted: Mon Aug 27, 2007 7:29 am
by shiznatix
I am looking for a way to take the NOW() function and subtract 2 days from it but still keep the timestamp in the same format. Basically I have this query:

Code: Select all

SELECT
	bo.id, bo.bonus_code, rm.title
FROM
	rb_bonus_offers AS bo
LEFT JOIN
	rb_rooms AS rm
ON
	bo.fk_room_id = rm.id
WHERE
	bo.active = "1"
AND
	bo.never_expires = "0"
AND
	bo.expiration_date < NOW()
but I want to get WHERE bo.expiration_date < NOW() - 2 days so I can have the data on bonus offers that will expire within 2 days. How do I go about that?

Posted: Mon Aug 27, 2007 7:40 am
by xpgeek
Shoot

Code: Select all

SELECT
        bo.id, bo.bonus_code, rm.title
FROM
        rb_bonus_offers AS bo
LEFT JOIN
        rb_rooms AS rm
ON
        bo.fk_room_id = rm.id
WHERE
        bo.active = "1"
AND
        bo.never_expires = "0"
AND
        bo.expiration_date < DATE_SUB(NOW(), 2 DAYS)

Posted: Mon Aug 27, 2007 7:48 am
by shiznatix
Thanks for the kick in the right direction. This was the final trick winner:

Code: Select all

DATE_SUB(NOW(), INTERVAL 2 DAY)

Posted: Mon Aug 27, 2007 3:59 pm
by feyd
Just a note: you can do the math inline, without the function.

Code: Select all

NOW() - INTERVAL 2 DAY