Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7010467
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:59:40+00:00 2026-05-27T21:59:40+00:00

I’ve created an SQL user defined function to determine if a given date is

  • 0

I’ve created an SQL user defined function to determine if a given date is a Japanese holiday. It now consists of a monstrosity of functions that call the same inline view for the *n*th time and it does not look very wise. While I know the best real-life solution is to build a calendar table, I wouldn’t dare to scrap all the code lines I have written. I look forward to refactoring ideas. Thanks.

Function isholiday(d) just bundles three functions; each defining three types of Japanese holidays.

DELIMITER //
CREATE FUNCTION isholiday(d date) RETURNS int
BEGIN
DECLARE t int;
CASE WHEN isregularholiday(d) = 1
          THEN SET t = 1;
     WHEN iscarryoverholiday(d) = 1
          THEN SET t = 1;
     WHEN isdentholiday(d) = 1
          THEN SET t = 1;
     ELSE SET t = 0; END CASE;
RETURN t;
END
//

isregularholiday(d) looks like this:

DELIMITER //
CREATE FUNCTION isregularholiday(d date) RETURNS int
BEGIN
DECLARE s int;
DECLARE t int;
SELECT count(*) INTO s
  FROM (SELECT holiday_desc
             , CASE WHEN SUBSTR(holiday_date, 3, 1) = '-'
                         THEN CAST(CONCAT_WS('-', YEAR(d), holiday_date) AS DATE)
                    WHEN holiday_date = 'ATH21'
                         THEN ATHLETIC_DATE(d)
  /*There are six mobile holidays but I shall spare you the other five. */     
               ELSE NULL END cnvt
          FROM holidays
         WHERE YEAR(d) BETWEEN valid_from AND valid_to) **base**
 WHERE cnvt = d;
CASE s WHEN 1 THEN SET t = 1;
       ELSE SET t = 0;
END CASE;
RETURN t;
END
//

Function argument d (or its month-date value) is not directly matched with holiday_date column (cf. cnvt = d) because the exact dates of some holidays are functionally dependent on the year, hence the CASE expression that branches into several functions. The function will be referring to the inline view base all the time.

Now, besides the basic holidays there are two types of holidays and they are fickle. I tentatively call them carryover holidays and dent holidays. A carryover holiday is defined like this:
If a holiday H falls on a Sunday, the first non-holiday weekday is the carryover holiday of H. Since there are a few holidays clamped together, the first non-holiday weekday for H is not necessarily the next day or Monday.

A dent holiday is a weekday between two holidays. The carryover takes precedence over the dent holiday.

Because of mobile holidays both types of holidays are mobile and fickle and have to be calculated for the year. iscarryoverholiday(d) queries base and count the number of rows for a range between d and the Sunday just before d. If the count equals the date difference between d and the last Sunday, d is a carryover holiday.

isdentholiday(d) calls isregularholiday() for d, d-1 and d+1 (expected values for each argument being 0, 1, 1). It also calls iscarryoverholiday() for d (to get 0), so it reads base four times. Ah….

I won’t bother you with any more details. I am just wondering if I can do something smart and define a closest thing to a dynamic view on MySQL.

Thanks YOU for reading this far!

Just in case, holiday as used here excludes Sundays.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T21:59:41+00:00Added an answer on May 27, 2026 at 9:59 pm

    I wrote a script called Holiday List. Basically, it is a table UDF that is passed a year as a parameter and it returns a “holiday table” which I can then join against to find holidays. This could give you a start point and some thoughts on how to deal with holidays, and you could add your rules for Japanese holidays to the script…

    http://www.sqlservercentral.com/scripts/Date+Manipulation/74302/

    If you want the script and can’t get it at the above link, let me know and I’ll e-mail it to you… The script is written for Microsoft SQL, it might take a bit of code changes to work under mySQL, but there is nothing too fancy in the script

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I need to clean up various Word 'smart' characters in user input, including but
I need a function that will clean a strings' special characters. I do NOT
I want to construct a data frame in an Rcpp function, but when I
Basically, what I'm trying to create is a page of div tags, each has
I am trying to understand how to use SyndicationItem to display feed which is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.