简体   繁体   中英

Mysql alternate week days

My table has the following columns

| customer_id | service_start_date |

I want to provide the service on alternate week days from the service start date (eg:- every other mondays, every other tuesdays etc..)

If the service_start_date is a monday, then the service will be delivered on every other mondays.

Is there any way to query the mysql table to get all customer_id s who needs service on a particular date?

Try something like

SELECT customer_id
FROM Table as t
WHERE MOD(DATEDIFF(DATE(NOW()), DATE(service_start_date)), 14) = 0

This is assuming that your service_start_date is always a weekday.

Addition to Clami219s answer:

To get the customer(s) that need service on a particular date (as of your request), use

SELECT customer_id
FROM table_name
WHERE
   service_start_date <= NOW() AND
   WEEKDAY(service_start_date) = WEEKDAY('2014-06-25'); //whatever date you like to fetch

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM