Day of week SQL
There are different ways you could get this info ..
1.
SELECT CASE WHEN (DATE - DATE '1900-01-01') MOD 7 = 0 THEN 'Monday'
WHEN (DATE - DATE '1900-01-01') MOD 7 = 1 THEN 'Tuesday'
WHEN (DATE - DATE '1900-01-01') MOD 7 = 2 THEN 'Wednesday'
WHEN (DATE - DATE '1900-01-01') MOD 7 = 3 THEN 'Thursday'
WHEN (DATE - DATE '1900-01-01') MOD 7 = 4 THEN 'Friday'
WHEN (DATE - DATE '1900-01-01') MOD 7 = 5 THEN 'Saturday'
WHEN (DATE - DATE '1900-01-01') MOD 7 = 6 THEN 'Sunday'
END AS DAY_OF_WEEK;
2.
SELECT day_of_week FROM sys_calendar.calendar WHERE calendar_date = DATE;
3.
SELECT
SUBSTRING('Monday Tuesday Wednesday Thursday Friday Saturday Sunday '
FROM (1+10*((DATE - DATE '1900-01-01') MOD 7)) FOR 10)
AS DAY_OF_WEEK;
1.
SELECT CASE WHEN (DATE - DATE '1900-01-01') MOD 7 = 0 THEN 'Monday'
WHEN (DATE - DATE '1900-01-01') MOD 7 = 1 THEN 'Tuesday'
WHEN (DATE - DATE '1900-01-01') MOD 7 = 2 THEN 'Wednesday'
WHEN (DATE - DATE '1900-01-01') MOD 7 = 3 THEN 'Thursday'
WHEN (DATE - DATE '1900-01-01') MOD 7 = 4 THEN 'Friday'
WHEN (DATE - DATE '1900-01-01') MOD 7 = 5 THEN 'Saturday'
WHEN (DATE - DATE '1900-01-01') MOD 7 = 6 THEN 'Sunday'
END AS DAY_OF_WEEK;
2.
SELECT day_of_week FROM sys_calendar.calendar WHERE calendar_date = DATE;
3.
SELECT
SUBSTRING('Monday Tuesday Wednesday Thursday Friday Saturday Sunday '
FROM (1+10*((DATE - DATE '1900-01-01') MOD 7)) FOR 10)
AS DAY_OF_WEEK;
Labels: day of week, sql, teradata
1 Comments:
Here is another SQL for WeekDay
SELECT CAST(CAST(DATE AS FORMAT 'E4') AS CHAR(9)) WeekDay ;
Post a Comment
Subscribe to Post Comments [Atom]
<< Home