Re: Weeks

2009-12-29 Thread DaWiz
If all you want is the current week then the query is simple: SELECT * FROM orders where WEEK(orders.order_date) = WEEK(NOW()) The default is thje day starts on Sunday so the second value is not needed. WEEK(NOW(),7) is equivalent to WEEK(NOW(),0) - the valid values are 0 - 6. As for performa

Re: Weeks

2009-12-29 Thread Peter Brawley
ML, trying to write some SQL that will give me records for the CURRENT WEEK. Example, starting on a Sunday and going through Saturday. This week it would be Dec 27 - Jan 2. For the week of any date @d: ... WHERE order_date BETWEEN AddDate(@d, -DayOfWeek(@d)+1) AND AddDate(@d, 7-DayOfWeek(@d

RE: Weeks

2009-12-28 Thread Gavin Towey
See: http://gtowey.blogspot.com/2009/04/how-to-select-this-wednesday-or-other.html just calculate the two dates, and use WHERE order_date BETWEEN (calculated start date) AND (calculated end date) This avoids using functions on the actual column when possible, since that will prevent using index