php - adddate(curdate(), -(day(curdate())-1)) and concat(last_day(curdate()),' 23:59:59') -


what mysql script means time between ?

     adddate(curdate(), -(day(curdate())-1)) , concat(last_day(curdate()),' 23:59:59') 

day(curdate())-1 current day of month, less 1. today (aug 15, 2013), value 14. subtract 14 days august 15 , have august 1. in other words, adddate(curdate(), -(day(curdate())-1)) gives first day of month.

last_day(curdate()) gives last day of month. if call today return august 31, 2013. append 23:59:59 , have last second of last day of month.

in other words, if called on august 15, 2013, values come out 2013-08-01 , 2013-08-31 23:59:59. if range applied against datetime value, means "anything in month of august 2013".

this pretty way check date/time values within month because avoids using function on mysql column holds date/time. if column has index, index (probably) used optimization. 1 approach see this:

where date_format(mydatetime, '%y%m') = date_format(curdate(), '%y%m') 

this reads little better, kills optimization. i'd stick expression have.


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -