views:

45

answers:

2

I am pulling in all the records from my customer database(mysql) for the last ten days
$offset1 =strtotime("-10 day"); $date3=date("Y-m-d",$offset1);

SELECT * FROM customers WHERE date between '$date3' and '$date' AND customer.custid = '$custid' ORDER by date DESC

I would like to leave out the dates falling on a saturday or sunday and would like to put this in my query rather than the php

If you can help thanks

+2  A: 

You can use the DayOfWeek function from MySQL.

SELECT * 
FROM customers 
WHERE date between '$date3' and '$date'
      AND DayOfWeek(date) <> 1
      AND DayOfWeek(date) <> 7
      AND customer.custid = '$custid' 
ORDER by date DESC
Jason Punyon
thanks just what I needed
bsandrabr
You might play with how to express the bound check on that to see if you can find a way to remove the pair of checks: `DayOfWeek(date) % 7 > 1`. As always, *benchmark* this as it is harder to read and the engine might do this for you.
BCS
thanks BCS that works even better
bsandrabr
+2  A: 

I think you can use the DAYNAME function:

AND DAYNAME(date) NOT IN ('Saturday', 'Sunday')

DAYNAME(date)

Leniel Macaferi
thanks I'll try that also
bsandrabr
string matches,.. yuck.
BCS