Displaying the day through a stored procedure
I have a problem with a MySQL stored procedure
table tbl_teachers
:
id dat_teacher_doj fk_int_dept_id
1 1982-01-10 1
2 1979-09-01 1
3 1981-10-13 1
here i need to create a stored procedure to find out the date the teachers joined and if on monday it should display on monday it should display "weekday"? I need an answer like:
call check date (1982-01-10) -> day day of the week
just an CASE
expression withDAYNAME
SELECT id, dat_teacher_doj,
CASE DAYNAME(dat_teacher_doj) WHEN 'Monday' THEN 'Monday' ELSE 'Weekday' END
FROM tbl_teachers
Procedure: this will work in localhost phpmyadmin
as wellworkbench
CREATE PROCEDURE `GetWeekDay`(IN `paramDate` DATE)
NO SQL
SELECT CASE DAYNAME(paramDate) WHEN 'Monday' THEN 'Monday' ELSE 'Weekday' END AS 'WkDy'
Call
CALL `GetWeekDay`('2015-08-03');
You don't need a stored procedure for this. A simple expression case
around the call dayofweek
should do the trick:
SELECT id, dat_teacher_doj,
CASE DAYOFWEEK(dat_teacher_doj) WHEN 2 THEN 'Monday' ELSE 'Weekday' END
FROM tbl_teachers