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

  • SEARCH
  • Home
  • 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 5947887
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T17:01:44+00:00 2026-05-22T17:01:44+00:00

I would like to ask if there is a smart or easy way to

  • 0

I would like to ask if there is a smart or easy way to get the first and last weekday of a month in MySQL. In other way, I want to avoid Weekends and shift first or last day properly.

For example:

For the period: 2011-05-01 till 2011-05-31
First weekday should be: 2011-05-02 and not 2011-05-01 as 2011-05-01 is Sunday.
Last weekday should be: 2011-05-31 as it is Tuesday.

For the period: 2011-04-01 till 2011-04-30,
First weekday: 2011-04-01
Last weekday: 2011-04-29
  • 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-22T17:01:45+00:00Added an answer on May 22, 2026 at 5:01 pm

    How about defining functions FIRST_WDOM() (week/work day of month) and LAST_WDOM() in the style of LAST_DAY()?

    DELIMITER //
    CREATE FUNCTION first_wdom (d DATETIME) -- First work/week day of month
    RETURNS DATE DETERMINISTIC
    BEGIN
      DECLARE first_dom DATE;
      SET first_dom = DATE_FORMAT(d, '%Y-%m-01');
    
      RETURN first_dom + INTERVAL (CASE DAYOFWEEK(first_dom)
                                   WHEN 1 THEN 1
                                   WHEN 7 THEN 2
                                   ELSE 0
                                   END) DAY;
    END //
    CREATE FUNCTION last_wdom (d DATETIME) -- Last work/week day of month
    RETURNS DATE DETERMINISTIC
    BEGIN
      DECLARE last_dom DATE;
      SET last_dom = LAST_DAY(d);
    
      RETURN last_dom - INTERVAL (CASE DAYOFWEEK(last_dom)
                                  WHEN 1 THEN 2
                                  WHEN 7 THEN 1
                                  ELSE 0
                                  END) DAY;
    END //
    DELIMITER ;
    
    mysql> SELECT FIRST_WDOM('2011-05-10'), LAST_WDOM('2011-05-10');
    +--------------------------+-------------------------+
    | FIRST_WDOM('2011-05-10') | LAST_WDOM('2011-05-10') |
    +--------------------------+-------------------------+
    | 2011-05-02               | 2011-05-31              | 
    +--------------------------+-------------------------+
    1 row in set (0.01 sec)
    

    This is merely an adaptation of ic3b3rg’s answer, and assumes that Saturday and Sunday are your weekend days. I use DATETIME, rather than DATE, as the input type to avoid truncation warnings when passing in, say, NOW().

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

Sidebar

Related Questions

I would like ask if there's a way to download an android layout from
I would like to ask is there any way to achieve this functionality: I
I would like to ask if there is a way to see a variable
I would like to ask if there is a more elegant way to write
I would like to ask if there is any tools for Google App Engine
I would like to ask is this code thread safe? There is a problem
First off, before I ask, i would like to point out that this question
I would like to ask is there any software or script able to do
What I would like ask is best illustrated by an example, so bear with
I would like to ask which is the best solution for integrating google maps

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.