开发者

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

开发者 https://www.devze.com 2023-03-10 09:36 出处:网络
How do I obtain the 1st and 15th day of each month for a period between two dates? Exampl开发者_如何学Pythone that does not work:

How do I obtain the 1st and 15th day of each month for a period between two dates? Exampl开发者_如何学Pythone 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号