# of weekdays before sysdate?

# of weekdays before sysdate?

Post by Doug O'Lea » Sun, 31 Dec 1899 09:00:00



Hey;

Is there a way to identify the number of weekdays since the beginning of
the year that's somewhat easier (and, hopefully, more accurate) than I'm
coming up with?

What I've got so far is:

-- Gives the day's number in the year.
select to_char(sysdate,'DDD') from dual

-- The hack at the # of weekends in the year so far
-- Multiply the number of weeks * 2 on the theory that
-- each week has a weekend, ergo...
select to_char(sysdate,'WW') * 2 from dual;

--Combining the two:
select (to_char(sysdate,'DDD') - (to_char(sysdate,'WW') * 2)) from dual;

That sql results in 49 (as of Saturday, 3/11/00).  However, according to
my calendar, there's been 50 weekdays since the beginning of the year.  
If all else fails, I'll add a fudge factor; however, I'd like a cleaner
method of figuring that out...

This bit of ugliness is going to be part of a script that identifies
contractors' (particularly mine!) billing percentages.  I'd like it to be
accurate.

Thanks for any tips/suggestions.

Doug

PS:  In case anyone's concerned, I get billed out as a UNIX admin, not an
Oracle dba...

--
==============
Douglas K. O'Leary
Senior System Admin

==============

 
 
 

# of weekdays before sysdate?

Post by Thomas J. Kyt » Sun, 31 Dec 1899 09:00:00




Quote:> Hey;

> Is there a way to identify the number of weekdays since the beginning
of
> the year that's somewhat easier (and, hopefully, more accurate) than
I'm
> coming up with?

> What I've got so far is:

> -- Gives the day's number in the year.
> select to_char(sysdate,'DDD') from dual

> -- The hack at the # of weekends in the year so far
> -- Multiply the number of weeks * 2 on the theory that
> -- each week has a weekend, ergo...
> select to_char(sysdate,'WW') * 2 from dual;

> --Combining the two:
> select (to_char(sysdate,'DDD') - (to_char(sysdate,'WW') * 2)) from
dual;

> That sql results in 49 (as of Saturday, 3/11/00).  However, according
to
> my calendar, there's been 50 weekdays since the beginning of the
year.
> If all else fails, I'll add a fudge factor; however, I'd like a
cleaner
> method of figuring that out...

> This bit of ugliness is going to be part of a script that identifies
> contractors' (particularly mine!) billing percentages.  I'd like it
to be
> accurate.

> Thanks for any tips/suggestions.

> Doug

> PS:  In case anyone's concerned, I get billed out as a UNIX admin,
not an
> Oracle dba...

select count(*)
  from ( select trunc(sysdate,'year')+rnum-1
           from ( select rownum rnum
                    from all_objects
                   where rownum <= to_char(sysdate,'ddd') )
          where to_char( trunc(sysdate,'year')+rnum-1, 'd' )
                        not in ( '1', '7' )
       )
/

That

o create a set of rnums from 1 .. number of days in the year so far
(counts on the fact that all_objects has more then 366 rows).

o then, from that set, keeps rows such that the
first_day_of_the_year+rnum-1 is not a saturday or sunday.

o then counts those rows....

> --
> ==============
> Douglas K. O'Leary
> Senior System Admin

> ==============

--

Oracle Service Industries
http://osi.oracle.com/~tkyte/index.html
--
Opinions are mine and do not necessarily reflect those of Oracle Corp

Sent via Deja.com http://www.deja.com/
Before you buy.

 
 
 

1. Weekday

Hi,
I started creating cubes last week, so I'm very new at
this.  One of the cubes I'm creating shows sales by week.  
The problem is that our week starts on Mondays and the
default is for Sundays.  How do I change the default?
Please help.

Thanks!

2. Hyperion--read locks

3. Weekday start from Monday, How to?

4. how to use edit mode in query analyzer

5. Sales by Weekdays

6. user defined functions

7. Calc 20 Day Avg - Weekdays only

8. parsing html string?

9. Select Distinct Date by Weekday and Date Range

10. Weekdays

11. Weekdays (M-F)

12. Weekday function

13. DATEADD, counting only weekdays...