php - how do I get month from date in mysql -


i want able fetch results mysql statement this:

select *    table   amount > 1000  

but want fetch result constrained month , year (based on input user)... trying this:

select *    table   amount > 1000     , datestart = month('$m')    

...$m being month gave error.

in table, have 2 dates: startdate , enddate focusing on startdate. input values month , year. how phrase sql statement gets results based on month of year?

you close - got comparison backwards (assuming startdate datetime or timestamp data type):

select *    table   amount > 1000     , month(datestart) = {$m} 

caveats:


alternatives:


because using functions on columns can't use indexes, better approach use between , str_to_date functions:

where startdate between str_to_date([start_date], [format])                      , str_to_date([end_date], [format]) 

see documentation formatting syntax.

reference:



Comments

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -