简体   繁体   中英

how to date1 and 15 of each month on mysql

I have a table named request that user submit their requests, i will like to get info of all request from first 15 days of the current month and after the 15 days are done the rest of the same month and so an for every month when i'm on the current month.

SELECT * 
FROM request
WHERE req_date >= curdate() - INTERVAL DAYOFWEEK(curdate()) + 15 DAY
AND req_date < curdate() - INTERVAL DAYOFWEEK(curdate())- 1 DAY;

this is why I found for pass weeks but is based on current date and I need it to be based on the 1 of the month and 15 of the same month so I can know what happened in the month divided in 2 periods

this is for the first 15

SELECT * FROM request 
WHERE
req_date between  CAST(DATE_FORMAT(NOW() ,'%Y-%m-01') as DATE)   
        and  CAST(DATE_FORMAT(NOW() ,'%Y-%m-15') as DATE)
;

and this for the second half month

SELECT * FROM request 
WHERE
req_date between  CAST(DATE_FORMAT(NOW() ,'%Y-%m-16') as DATE)   
        and LAST_DAY(DATE_ADD(NOW(), INTERVAL 1 MONTH))
;

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