MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

dayname

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database
View previous topic :: View next topic  
Author Message
misi
Beginner


Joined: 14 Apr 2004
Posts: 13
Topics: 10

PostPosted: Thu Apr 29, 2004 8:40 am    Post subject: dayname Reply with quote

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
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12376
Topics: 75
Location: San Jose

PostPosted: Thu Apr 29, 2004 9:31 am    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail Visit poster's website
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12376
Topics: 75
Location: San Jose

PostPosted: Thu Apr 29, 2004 9:33 am    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group