Need help with dayofweek function

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • cindilee715
    New Member
    • Sep 2008
    • 1

    Need help with dayofweek function

    I am trying to calculate the number of Mondays, Tuesdays, Wednesdays, etc in any given month. Example...in September 2008 there are 5 Mondays. 4 Fridays, etc. Does anyone know a SQL statement that does this.
  • docdiesel
    Recognized Expert Contributor
    • Aug 2007
    • 297

    #2
    Hi,

    I think there's no easy sql to calculate this. But you may use some date related functions to calculate what you need:

    Given you've got to calculate the number of weekdays for February 2008:
    Code:
    select day(date('[B]2008-02[/B]-01') + 1 month - 1 day) from sysibm.sysdummy1
    gives you the number of days in the given month, resulting in an integer from 28 to 31.
    Code:
    select dayofweek_iso(date('2008-02-01')) from sysibm.sysdummy1
    gives you the number of the day of the week for the first of the month (1=Monday, 7=Sunday), so you can calculate which days count up to 5 instead of 4.

    Please let us know how you solved it so that others may participate.

    Regards


    Doc Diesel

    Comment

    Working...