View previous topic :: View next topic |
Author |
Message |
misi Beginner
Joined: 14 Apr 2004 Posts: 13 Topics: 10
|
Posted: Thu Apr 29, 2004 8:40 am Post subject: dayname |
|
|
Can I get the dayname using sql or in a pgm? I am reading a db2 table which has a date column and I want to know the dayname on which this date falls. The date can be any date. My processing differs according to the dayname. is it possible?
misi |
|
Back to top |
|
|
kolusu Site Admin
Joined: 26 Nov 2002 Posts: 12375 Topics: 75 Location: San Jose
|
Posted: Thu Apr 29, 2004 9:31 am Post subject: |
|
|
Misi,
There are several ways of getting the day of the week. You can do it in db2 itself or you can do it the cobol program itself.
In DB2 we use the scalar function DAYOFWEEK to get the dayname. The DAYOFWEEK function returns an integer in the range of 1 to 7 that represents the day of the week where 1 is Sunday and 7 is Saturday.
Code: |
SELECT DAYOFWEEK(DB2-COLUMN)
FROM TABLE
;
|
Check this link for detailed explanation of the scalar function DAYOFWEEK
cobol code:
Code: |
01 WS-COB-DATE PIC 9(08).
01 WS-DIVIDE-ANSWER PIC S9(08) COMP.
01 WS-INTEGER PIC S9(08) COMP.
01 WS-REMAINDER PIC S9(04) COMP.
01 WS-DAY-OF-WEEK PIC X(09).
NOTE: ws-cob-date should be of the format CCYYMMDD
MOVE 20010429 TO WS-COB-DATE
COMPUTE WS-INTEGER = FUNCTION
INTEGER-OF-DATE(WS-COB-DATE)
DIVIDE WS-INTEGER BY 7 GIVING WS-DIVIDE-ANSWER
REMAINDER WS-REMAINDER
ADD 1 TO WS-REMAINDER
EVALUATE WS-REMAINDER
WHEN 1
MOVE 'SUNDAY ' TO WS-DAY-OF-WEEK
WHEN 2
MOVE 'MONDAY ' TO WS-DAY-OF-WEEK
WHEN 3
MOVE 'TUESDAY ' TO WS-DAY-OF-WEEK
WHEN 4
MOVE 'WEDNESDAY' TO WS-DAY-OF-WEEK
WHEN 5
MOVE 'THURSDAY ' TO WS-DAY-OF-WEEK
WHEN 6
MOVE 'FRIDAY ' TO WS-DAY-OF-WEEK
WHEN 7
MOVE 'SATURDAY ' TO WS-DAY-OF-WEEK
END-EVALUATE
DISPLAY 'IT IS A ' WS-DAY-OF-WEEK ' ON ' WS-COB-DATE
|
Check this link for a detailed explanation of the intrinsic function INTEGER-OF-DATE
Hope this helps...
Cheers
Kolusu _________________ Kolusu
www.linkedin.com/in/kolusu |
|
Back to top |
|
|
kolusu Site Admin
Joined: 26 Nov 2002 Posts: 12375 Topics: 75 Location: San Jose
|
Posted: Thu Apr 29, 2004 9:33 am Post subject: |
|
|
Ravi,
A simpler version of your sql would be as follows.
Code: |
SELECT (CASE DAYOFWEEK('2004-04-29')
WHEN 1 THEN 'SUNDAY'
WHEN 2 THEN 'MONDAY'
WHEN 3 THEN 'TUESDAY'
WHEN 4 THEN 'WEDNESDAY'
WHEN 5 THEN 'THURSDAY'
WHEN 6 THEN 'FRIDAY'
WHEN 7 THEN 'SATURDAY'
END) AS WEEKDAY
FROM SYSIBM.SYSDUMMY1;
|
Kolusu _________________ Kolusu
www.linkedin.com/in/kolusu |
|
Back to top |
|
|
|
|