List:General Discussion« Previous MessageNext Message »
From:Gavin Towey Date:December 29 2009 12:26am
Subject:RE: Weeks
View as plain text  
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 indexes to find your query results.

Regards,
Gavin Towey

-----Original Message-----
From: ML [mailto:mailinglists@stripped]
Sent: Monday, December 28, 2009 4:15 PM
To: mysql@stripped
Subject: Weeks

Hi All,

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.

I am doing this so I can write a query that will show orders that are placed during the
current week.

Here is what I have, but this is showing from today for the next seven days.

SELECT * FROM orders WHERE WEEK(NOW(), 7) = WEEK(orders.order_date, 7)
 AND DATEDIFF(NOW(),orders.order_date) < 7;

Would anyone have any advice?

-Jason


--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/mysql?unsub=1


This message contains confidential information and is intended only for the individual
named.  If you are not the named addressee, you are notified that reviewing,
disseminating, disclosing, copying or distributing this e-mail is strictly prohibited. 
Please notify the sender immediately by e-mail if you have received this e-mail by
mistake and delete this e-mail from your system. E-mail transmission cannot be guaranteed
to be secure or error-free as information could be intercepted, corrupted, lost,
destroyed, arrive late or incomplete, or contain viruses. The sender therefore does not
accept liability for any loss or damage caused by viruses or errors or omissions in the
contents of this message, which arise as a result of e-mail transmission. [FriendFinder
Networks, Inc., 220 Humbolt court, Sunnyvale, CA 94089, USA, FriendFinder.com
Thread
WeeksML29 Dec
  • RE: WeeksGavin Towey29 Dec
  • Re: WeeksPeter Brawley29 Dec
  • Re: WeeksDaWiz30 Dec