date - MySQL: Returning records from the current month and previous 3 months -


i'm using php/mysql booking system , i'm using google line chart try , display gross sales current month, , previous 3 months.

each booking has date in standard phpmyadmin "date" format, yyyy:mm:dd.

so, im looking 4 results 4 queries, each query filtering out month , grabbing sum of each booking month.

my question is, how can distinguish between months in query? how structure query?

based on title:

select * bookings month(curdate())=month(booking_date); select * bookings month(booking_date) > month(curdate()-interval 3 month) , < month(curdate() + interval 1 month); 

for simple per-month searches can use following:

select * bookings monthname(booking_date)='july' , year(booking_date)=2013; 

or:

select * bookings month(booking_date)=7 , year(booking_date)=2013; 

also since you've got months, (this method requires maintain table of ending dates each month compensate leap year though):

select * bookings booking_date>'2013-06-30' , booking_date<'2013-08-01'; 

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -