php - Between date in Mysql not working properly -


i want filter items based on 2 different dates using mysql. in database store data 2017-03-28 10:55:10. need date part, not time used date() function:

select sum(cashamount) sumcashsalesamount,        date(transactiondate) datepart  master_transaction  transactiondate between '2017-02-22%' , '2017-03-28%'  order transactiondate desc 

above query have 2 dates 2017-02-22% , 2017-03-28% return no result.

but when change 2017-03-28% date 2017-03-29% (tomorrow date) results.

don't use between "dates". put in quotes, because values datetime values.

the best way write condition is:

where transactiondate >= '2017-02-22' ,       transactiondate < '2017-03-29'  

note inequality second condition. between inclusive, include midnight on 2017-03-28.

why best?

  • it allows query optimizer take advantage of indexes , partitions.
  • it logic want.
  • it works both date , datetime types.

Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -