Evaluate Weigh the pros and cons of technologies, products and projects you are considering.

DB2 SQL to return name of the day of the week

Use the CASE statement to return the day of the week for a given date.

This SQL statement uses the CASE statement to return the name of the weekday for a given date. Note that the example uses CURRENT DATE special register, but you can substitute a literal or host variable.

 

SELECT CURRENT DATE, 
CASE                                    
WHEN (DAYS(CURRENT DATE) - (DAYS(CURRENT DATE)/7)*7) = 0         
THEN 'SUNDAY'                           
WHEN (DAYS(CURRENT DATE) - (DAYS(CURRENT DATE)/7)*7) = 1         
THEN 'MONDAY'                           
WHEN (DAYS(CURRENT DATE) - (DAYS(CURRENT DATE)/7)*7) = 2         
THEN 'TUESDAY'                                           
WHEN (DAYS(CURRENT DATE) - (DAYS(CURRENT DATE)/7)*7) = 3         
THEN 'WEDNESDAY'                                               
WHEN (DAYS(CURRENT DATE) - (DAYS(CURRENT DATE)/7)*7) = 4         
THEN 'THURSDAY'                                                
WHEN (DAYS(CURRENT DATE) - (DAYS(CURRENT DATE)/7)*7) = 5         
THEN 'FRIDAY'                                               
WHEN (DAYS(CURRENT DATE) - (DAYS(CURRENT DATE)/7)*7) = 6         
THEN 'SATURDAY'                                                
END AS DAY 
FROM SYSIBM.SYSDUMMY1

Results from above:

04/03/2001 TUESDAY

More on this topic


 

Dig Deeper on DB2 UDB (universal databases)

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.

-ADS BY GOOGLE

SearchDataCenter

Close