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
- What do you think about this tip? E-mail us at editor@searchDatabase.com with your feedback.
- The Best IBM DB2 Web Links: tips, tutorials, scripts, and more.
- Have a DB2 tip to offer your fellow DBA's and developers? The best tips submitted will receive a cool prize--submit your tip today!
- Ask your technical DB2 questions--or help out your peers by answering them--in our live discussion forums.
- Ask the Experts yourself: Our DB2 gurus are waiting to answer your technical questions.