sql - Number of particular days between two dates -
is there "easy" way calculate count of particular day between 2 dates (e.g., wanted know number of tuesdays between 1st january, 2000 , today)? moreover, same question applies more broadly different units (e.g., how many 2pms between 2 dates, how many februaries, how many 21st augusts, etc.)... best i've come (for days between dates) this:
with calendar ( select to_char(:start + level - 1, 'day') dayofweek dual connect level <= ceil(:end - :start) ) select dayofweek, count(dayofweek) calendar group dayofweek; i have create view of -- hardcoding start , end dates -- make convenient(ish) use; either or write function dirty work. wouldn't difficult, i'm wondering if there's oracle function this, accounting things leap days, etc.
edit this popped in related links when posted this. more-or-less answers question days , know there's months_between function use particular months. other related functions should know about?
replace start/end dates dates. query calc number of tue jan 1-2013 till today, 18:
select count(*) number_of_tue ( select trunc(to_date(sysdate), 'year') + level-1 start_dt , to_char(trunc(to_date(sysdate), 'year') + level - 1, 'dy') wk_day , to_char(trunc(to_date(sysdate), 'year') + level - 1, 'd') wk_day# , trunc(sysdate) end_dt dual connect level <= trunc(sysdate) - trunc(sysdate, 'year') -- replace start/end dates ) wk_day# = 3 -- or wk_day = 'tue' -- /
Comments
Post a Comment