Created
May 29, 2015 19:05
-
-
Save fbidu/9f789957c69b5fefbbb3 to your computer and use it in GitHub Desktop.
Draft of a function that returns the first weekday of a month
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DROP FUNCTION first_week_day; | |
DELIMITER // | |
CREATE FUNCTION first_week_day (year INT, month INT, weekday_index INT) | |
RETURNS VARCHAR(10) | |
DETERMINISTIC | |
BEGIN | |
DECLARE day_number INT DEFAULT 1; | |
DECLARE date_string VARCHAR(10); | |
SET date_string = CONCAT(convert(year, char), "-", convert(month, char), "-", convert(day_number, char)); | |
return date_string; | |
END | |
// | |
SELECT STR_TO_DATE(first_week_day(2015, 29, 0), '%d/%m/%Y'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment