i need query results table has 2 columns
column startdt (datetime), column enddt (datetime) there records startdt 2013-07-19 , enddt 2013-07-29
i need records weekday = 1 (tuesday)
record date 2013-07-19 weekday 4 , ends 2013-07-29 0
actually want results has weekday monday or weekday.
you can check above link example http://sqlfiddle.com/#!2/a80ce/1
if don't understand want let me explain. have event starts july 15 , ends july 25. (starts monday , ends thursday) user selects 1 of week days (monday, tuesday etc). if select tuesday want query events active in tuesday.
i found answer if want check it
select articleid,startdt,enddt,dayofweek(startdt), datediff(enddt,startdt) datedf events (dayofweek(events.startdt) <= 3 , dayofweek(events.enddt) >= 3) or datediff(enddt,startdt) >=6
(3 number of weekday "tuesday")
how using comments other people gave , use query combines both dayofweek
, simple greater/smaller/equal syntax follows:
select * events dayofweek(events.startdt) <= 6 , dayofweek(events.enddt) >= 6
this gives following results if user specified friday (= 6):
articleid startdt enddt 4 july, 12 2013 00:00:00+0000 july, 26 2013 00:00:00+0000 6 july, 16 2013 00:00:00+0000 july, 20 2013 00:00:00+0000
i think better of using dayofmonth
(maybe me) makes clearer, possibly combining use of both ensure it's active on friday.
the op indicates events in history should retrieved , such following query wants:
select * events dayofweek(events.startdt) <= 6 , dayofweek(events.enddt) >= 6 or datediff(enddt,startdt) >=6
Comments
Post a Comment