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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T00:24:35+00:00 2026-06-13T00:24:35+00:00

I am given a start and end date. i want to count the number

  • 0

I am given a start and end date.

i want to count the number of weekdays between those 2 dates.

then in a table of dates, i want to count those in a similar fashion to to pick weekends only.

Could someone help me on this?

  • 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-06-13T00:24:36+00:00Added an answer on June 13, 2026 at 12:24 am

    One approach is to have a materialized table of days / dates. But this same method, used to build this materialized table, can be used directly in a query. I show a couple of [weekday] calculations, but you can use the same approach to query about weekend days (weekend day values are 5, and 6):

    Direct single query example:

    SELECT day
         , WEEKDAY(day) AS wkday
      FROM (
    SELECT FROM_DAYS(d.day1+v1.result) AS day
      FROM (SELECT TO_DAYS(DATE('2000-01-01')) AS day1
                 , TO_DAYS(DATE('2021-01-01')) AS day2
         ) AS d
      JOIN (
          SELECT v1.num+v2.num+v3.num+v4.num AS result
            FROM (
                     SELECT 1 AS num UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5
               UNION SELECT 6 UNION SELECT 7 UNION SELECT 8 UNION SELECT 9 UNION SELECT 0
               ) AS v1
            JOIN (
                     SELECT 10 AS num UNION SELECT 20 UNION SELECT 30 UNION SELECT 40 UNION SELECT 50
               UNION SELECT 60 UNION SELECT 70 UNION SELECT 80 UNION SELECT 90 UNION SELECT 00
               ) AS v2
            JOIN (
                     SELECT 100 AS num UNION SELECT 200 UNION SELECT 300 UNION SELECT 400 UNION SELECT 500
               UNION SELECT 600 UNION SELECT 700 UNION SELECT 800 UNION SELECT 900 UNION SELECT 000
               ) AS v3
            JOIN (
                     SELECT 1000 AS num UNION SELECT 2000 UNION SELECT 3000 UNION SELECT 4000 UNION SELECT 5000
               UNION SELECT 6000 UNION SELECT 7000 UNION SELECT 8000 UNION SELECT 9000 UNION SELECT 0000
               ) AS v4
         ) v1
     WHERE v1.result < (d.day2-d.day1)
         ) AS days
     WHERE WEEKDAY(day) < 5
     LIMIT 10
    ;
    
    
    
    USE test;
    
    DROP TABLE IF EXISTS days;
    
    CREATE TABLE days (
       day   date PRIMARY KEY
    ) ENGINE = InnoDB;
    
    INSERT INTO days
    SELECT FROM_DAYS(d.day1+v1.result)
      FROM (SELECT TO_DAYS(DATE('2000-01-01')) AS day1
                 , TO_DAYS(DATE('2021-01-01')) AS day2
         ) AS d
      JOIN (
          SELECT v1.num+v2.num+v3.num+v4.num AS result
            FROM (
                     SELECT 1 AS num UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5
               UNION SELECT 6 UNION SELECT 7 UNION SELECT 8 UNION SELECT 9 UNION SELECT 0
               ) AS v1
            JOIN (
                     SELECT 10 AS num UNION SELECT 20 UNION SELECT 30 UNION SELECT 40 UNION SELECT 50
               UNION SELECT 60 UNION SELECT 70 UNION SELECT 80 UNION SELECT 90 UNION SELECT 00
               ) AS v2
            JOIN (
                     SELECT 100 AS num UNION SELECT 200 UNION SELECT 300 UNION SELECT 400 UNION SELECT 500
               UNION SELECT 600 UNION SELECT 700 UNION SELECT 800 UNION SELECT 900 UNION SELECT 000
               ) AS v3
            JOIN (
                     SELECT 1000 AS num UNION SELECT 2000 UNION SELECT 3000 UNION SELECT 4000 UNION SELECT 5000
               UNION SELECT 6000 UNION SELECT 7000 UNION SELECT 8000 UNION SELECT 9000 UNION SELECT 0000
               ) AS v4
         ) v1
     WHERE v1.result < (d.day2-d.day1)
    ;
    
    SELECT *
      FROM days
     ORDER BY day
     LIMIT 10
    ;
    
    
    SELECT COUNT(*) FROM days;
    
    SELECT MIN(day), MAX(day) FROM days;
    
    SELECT day, WEEKDAY(day) FROM days LIMIT 6;
    
    SELECT day, WEEKDAY(day) AS wkday FROM days WHERE WEEKDAY(day) < 5 LIMIT 6;
    
    SELECT COUNT(*), MIN(day), MAX(day) FROM days WHERE WEEKDAY(day) < 5;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given a table action(start:DATE, length:NUMBER, type:NUMBER), with all records unique, I need to select
A table exists in Microsoft SQL Server with record ID, Start Date, End Date
I have an appointments table which saves 2 times. start and end. I want
Given I have a model/table with appointments, saved as a date. I want to
My requirement is as follows: I want to give actor name, start date, end
Given DateTime start = startsomething and DateTime end = endSomething Is there a standard
Given just a std::string iterator, is it possible to determine the start and end
I need to determine if a given selection is in between a start line
I want to get all the movie ids and names for a given date
Using SQL Server 2005 I want to generate the table values between the two

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.