0

Possible Duplicate:
Get a list of dates between two dates

This is my sql:

select * from table as t 
where DateAndTime BETWEEN '2011-03-01' AND '2012-01-25'

Question: * For example, i need get data from January, 2012 for every day (except weekends).

How can i do it?

Community
  • 1
  • 1
remizpez
  • 3
  • 3

4 Answers4

0

try this.

SELECT * 
from table as t 
where (DateAndTime BETWEEN '2011-03-01' AND '2012-01-25') AND
       DateAndTime NOT IN ('2011-03-03', '2011-03-10') -- Put the excempted
                                                       -- dates here
John Woo
  • 258,903
  • 69
  • 498
  • 492
0
select * from table as t 
where DateAndTime BETWEEN '2011-03-01' AND '2012-01-25' 
AND (DATEPART(weekday, DateAndTime ) <> 1 and  DATEPART(weekday,DateAndTime ) <> 6)

(DATEPART(weekday, DateAndTime ) = 1 is sunday (DATEPART(weekday, DateAndTime ) = 6 is saturday

Ellen Tan
  • 53
  • 1
  • 1
  • 10
0
SELECT
    * 
FROM
    yourtable AS T 
WHERE 
    yourdatetimefield BETWEEN STR_TO_DATE('2012-01-01', '%Y-%m-%d') AND 
                              STR_TO_DATE('2012-12-31', '%Y-%m-%d')
AND 
    DAYOFWEEK(yourdatetimefield) <> 1 AND    '  Sunday
    DAYOFWEEK(yourdatetimefield) <> 7        '  Saturday 
GROUP BY
    DAY(yourdatetimefield);
vulkanino
  • 9,074
  • 7
  • 44
  • 71
0

try this query

SELECT * FROM tableName
WHERE DateAndTime BETWEEN '2011-03-01' AND '2012-01-25'
AND WEEKDAY(DateAndTime) <= 4
Naveen Kumar
  • 4,543
  • 1
  • 18
  • 36