Janith Chinthana
Janith Chinthana

Reputation: 3844

one month before and one day after in Mysql

I need to send notification emails for members when they about to expire their membership on one month before and a day after.

Eg: If membership expire on 20/08/2014 I need to send a mail on 21/07/2014

I used following logic to get one month condition,

membership_expires<DATE_ADD(NOW(),INTERVAL 1 MONTH)

But I don't know how to add one day condition on the same query.

Any help would be appreciate.

Upvotes: 1

Views: 836

Answers (3)

Janith Chinthana
Janith Chinthana

Reputation: 3844

thanks to @juergen and this answer I made up following clause

membership_expires>NOW() and membership_expires< DATE_SUB((DATE_ADD(NOW(),INTERVAL 1 MONTH)), INTERVAL 1 DAY)

Upvotes: 0

avisheks
avisheks

Reputation: 1180

How about this:

SELECT * FROM subscription 
WHERE
membership_expires = CURDATE() + interval 1 MONTH - interval 1 DAY;

Upvotes: 1

juergen d
juergen d

Reputation: 204794

where membership_expires = CURDATE() + interval 1 MONTH
   or membership_expires = CURDATE() - interval 1 DAY

Upvotes: 2

Related Questions