aarbrouk Posted March 26, 2009 Share Posted March 26, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/151275-sql-query-returning-back-rows-based-on-the-date-field/ Share on other sites More sharing options...
aarbrouk Posted March 26, 2009 Author Share Posted March 26, 2009 or how do I even query on a date time field based on anything?? Quote Link to comment https://forums.phpfreaks.com/topic/151275-sql-query-returning-back-rows-based-on-the-date-field/#findComment-794671 Share on other sites More sharing options...
KPH71 Posted March 26, 2009 Share Posted March 26, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/151275-sql-query-returning-back-rows-based-on-the-date-field/#findComment-794685 Share on other sites More sharing options...
aarbrouk Posted March 27, 2009 Author Share Posted March 27, 2009 I solved the problem another way, but thanks for your time and advice anyway... Quote Link to comment https://forums.phpfreaks.com/topic/151275-sql-query-returning-back-rows-based-on-the-date-field/#findComment-795108 Share on other sites More sharing options...
fenway Posted April 1, 2009 Share Posted April 1, 2009 I solved the problem another way, but thanks for your time and advice anyway... Then tell us. Quote Link to comment https://forums.phpfreaks.com/topic/151275-sql-query-returning-back-rows-based-on-the-date-field/#findComment-798559 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.