ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Get day of week in SQL

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Get day of week in SQL

    I saw this on another newsgroup. (Thanks Birgitta)

    Code:
    there are even easier methods to determine the day of week or week.
    SQL provides several Scalar Functions that can be easily used within RPG:
    1. DAYOFWEEK: Calculates the day of week (1=Sunday ... 7=Saturday) from any
    date field
    2. DAYOFWEEK_ISO: Calculates the day of week according the ISO definitions
    (1=Monday ... 7=Sunday)
    3. DAYNAME: Determines the name of the week day (Monday ... Sunday)
                The daynames are stored in a message file, that's why it can be
    used for each language
                On a German OS for example it will return (Montag ... Sonntag)
    4. WEEK: Calculates the week no., January, 1st is always in week 1
    5. WEEK_ISO: Calculates the week no. according the ISO definitions
                A week starts always with Monday.
                The first thursday of a year is always in week 1.
                January, 4th is always in week 1.
    
    C/EXEC SQL  Set :MyDayOfWeek = DAYOFWEEK(:MYDATE)
    C/END-EXEC
    
    C/EXEC SQL  Set :MyDatOfWeekIso = DAYOFWEEK_ISO(:MyDate)
    C/END-EXEC
    
    C/EXEC SQL  Set :MyDayName = DAYNAME(:MYDate)
    C/END-EXEC
    
    C/EXEC SQL  Set :MyWeekISO = WEEK_ISO(:MyDate)
    C/END-EXEC
    
    
    Mit freundlichen Gruessen / Best regards
    
    Birgitta
    All my answers were extracted from the "Big Dummy's Guide to the As400"
    and I take no responsibility for any of them.

    www.code400.com
Working...
X