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 1005709
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T08:20:28+00:00 2026-05-16T08:20:28+00:00

How do you most easily calculate how many e.g. Mondays are left in a

  • 0

How do you most easily calculate how many e.g. Mondays are left in a month using MySQL (counting today)?

Bonus points for a solution that solves it for all days of the week in one query.

Desired output (run on Tuesday August 17th 2010):

dayOfWeek   left
1           2      -- Sunday
2           2      -- Monday
3           3      -- Tuesday (yep, including today)
4           2      -- Wednesday
5           2      -- Thursday
6           2      -- Friday
7           2      -- Saturday
  • 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-16T08:20:29+00:00Added an answer on May 16, 2026 at 8:20 am

    Create a date table that contains one row for each day that you care about (say Jan 1 2000 – Dec 31 2099):

    create table dates (the_date date primary key);
    
    delimiter $$
    
    create procedure populate_dates (p_start_date date, p_end_date date)
    begin
    declare v_date date;
    set v_date = p_start_date;
    while v_date <= p_end_date
    do
      insert ignore into dates (the_date) values (v_date);
      set v_Date = date_add(v_date, interval 1 day);
    end while;
    end $$
    
    delimiter ;
    
    call populate_dates('2000-01-01','2099-12-31');
    

    Then you can run a query like this to get your desired output:

    set @date = curdate();
    
    select dayofweek(the_date) as dayOfWeek, count(*) as numLeft 
    from dates 
    where the_date >= @date
    and the_date <  str_to_date(period_add(date_format(@date,'%Y%m'),1),'%Y%m') 
    group by dayofweek(the_date);
    

    That will exclude days of the week that have 0 occurrences left in the month. If you want to see those you can create another table with the days of the week (1-7):

    create table days_of_week (
      id tinyint unsigned not null primary key, 
      name char(10) not null
    );
    
    insert into days_of_week (id,name) values (1,'Sunday'),(2,'Monday'),
      (3,'Tuesday'),(4,'Wednesday'),(5,'Thursday'),(6,'Friday'),(7,'Saturday');
    

    And query that table with a left join to the dates table:

    select w.id, count(d.the_Date) as numLeft 
    from days_of_week w 
    left outer join dates d on w.id = dayofweek(d.the_date) 
      and d.the_date >= @date 
      and d.the_date <  str_to_date(period_add(date_format(@date,'%Y%m'),1),'%Y%m') 
    group by w.id;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I noticed that most of the time, when using some encoding other than 'the
I have another question which i think is most easily solved by using javascript
when loading my form (from variables) i can easily set the value of most
This is easily one of the most annoying features of Visual Studio in its
I am trying to find the fastest and most efficient way to calculate slopes
What can be done to access remote domain most easily to read data with
What is the most important features a IOC container should contain? You can easily
How can I drop tables most easily from GAE datastore?
Most apps have some kind of preferences or user settings that can be stored
Possible Duplicate: How do you easily horizontally center a <div> using CSS? I have

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.