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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T01:43:54+00:00 2026-05-31T01:43:54+00:00

I had a problem but part was solving thanks to this question , but

  • 0

I had a problem but part was solving thanks to this question, but know i want to know how can i count the days beetween a given interval.

It is a query to count how many days an employee goes to vacation. So given (or not given) a date range, i would like count how many vacation days are beetween given interval.

Currenty my SQL is like this:

SELECT SUM(DATEDIFF(vacation_end_date,vacation_start_date))
FROM vacation WHERE vacation_end_date >= given_start_date 
AND vacation_start_date <= given_end_date'

I know thatthe DATEDIFF will only work for days inside given range, but it shouldn’t count days outside from given range.

Please help me, couldn’t find something similar on Stack Overflow.

  • 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-31T01:43:55+00:00Added an answer on May 31, 2026 at 1:43 am

    If vacation_end_date is the day the person is back from vacation and not his last day vacationing, the query to get the person’s vacation days between 2012-01-01 (inclusive) and 2013-01-01 (exclusive) would be;

    SELECT SUM(
     GREATEST(0, 
      DATEDIFF(
       LEAST('2013-01-01', vacation_end_date),
       GREATEST('2012-01-01', vacation_start_date)
    ))) 'VACATION_DAYS'
    FROM vacation;
    

    If vacation_end_date is his last vacation day, you’ll need to replace vacation_end_date with ADDDATE(vacation_end_date, INTERVAL 1 DAY)) in the query above to get the calculation correct.

    Simple demo here.

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

Sidebar

Related Questions

(I have a problem that I illustrated in this question but had no correct
I had this problem some time ago and I gave up but lately it
I had this problem before and can't for life of me remember how to
I had problem even in choosing a title for this question. Please feel free
I have a little problem. I had some JComboBox to a JDialog but they
i'm using jquery in report section in my asp.net mvc project.But i had problem
I had a problem with a part of my code, which after some iterations
Problem: I originally had a query that was working great but I'm now having
Ok I was a little unsure on how best name this problem :) But
I had this problem Cucumber scenarios for extremely long work flow And now I've

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.