Jump to content

sql query returning back rows based on the date field


aarbrouk

Recommended Posts

Hello,

 

I am trying to query an order table based on the "OrderDate" field... However I only want to return back these records based on each month

 

e.g. I want to return back a list of orders made in January when the link January is clicked... Could someone tell me the best way to go about this?

"OrderDate" is stored in Date time format e.g. 2009-03-25 00:00:00.

 

I want to pass through a variable and then do a query on this field but only based on the month

 

I was hoping to pass through a variable such as:

 

<a href="salesreportexcel.php?Month=01">January</a>

 

and then query the field based on that variable somehow... any suggestions? How would I perform the query based on such a value?

 

SELECT * FROM veeteesv1.order WHERE veeteesv1.order.OrderDate = ??????

 

Any help would be appreciated

I've never done this before so I haven't tested this but I believe that a query like this should be of use

 


$query = "SELECT MONTH(datetimefield) FROM table WHERE something='something'";

 

That should return the month number e.g. 3 or 11

 

Alternately you could try something like:

 


$query = "SELECT * FROM table WHERE MONTH(datetimefield)=$themonth";

 

If $themonth is something like 2 or 6 then this may work - (again only guessing here as I haven't done this type of thing before!)

 

Also I don't know whether MONTH works for datetimes - sorry I don't have time to try it out.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.