Jump to content

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.