Skip to content

Instantly share code, notes, and snippets.

@fbidu
Created May 29, 2015 19:05
Show Gist options
  • Save fbidu/9f789957c69b5fefbbb3 to your computer and use it in GitHub Desktop.
Save fbidu/9f789957c69b5fefbbb3 to your computer and use it in GitHub Desktop.
Draft of a function that returns the first weekday of a month
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