简体   繁体   中英

How to obtain the 1st and the 15th day of the month for each month (between 1 and 12) in mysql?

How do I obtain the 1st and 15th day of each month for a period between two dates? Example that does not work:

SELECT * FROM daily_data 
WHERE (`date` < '$des' AND `date` > '$has') 
  AND (`date` LIKE  '%-%-01' AND `date` LIKE '%-%-15');
 select * from table where day(date_field) in (1,15)

so your query I think it would become

select * FROM datos_diarios WHERE Fecha between '$des' and '$has' AND day(Fecha) in (1,15)

edit . Just for your knowledge it would be possible to use a wildcard char with like. Something like this:

select * from table 
where 
date_field like '____-__-01'
or 
date_field like '____-__-15'

but it's better if you use day() function.

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