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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:15:11+00:00 2026-05-27T06:15:11+00:00

I have to implement a solution where two date ranges can overlap each other.

  • 0

I have to implement a solution where two date ranges can overlap each other. within the overlapped dates, I have to count how many days overlap each other. Once I know the overlapped days I can calculate a total figure based on the price that’s attached per day.

A scenario would be that

A customer is booking a hotel

Customer booking dates – 17/02/2011 to 26/02/2011

Normal price (All year) – 01/01/2011 – 31/12/2011 (price per day :$30.00)

Special Offer 1 dates – 01/01/2011 to 19/02/2011 (price per day :$20.00)

Special Offer 2 dates – 17/02/2011 to 24/02/2011 (price per day :$10.00)

In the above scenario, the proposed algorithm should work out the cheapest offer that the date ranges overlap and work out the price for the booking. If there is no special offer available it uses the normal price.

So for the first two days the system should get the price from “special offer 1” as it’s the cheapest available price. Next 5 days should be “Special offer 2 price” and for the next 2 days it’ll be normal price.

I’d be grateful to see both SQL(using MS-SQL Server) or Code base answers to get the diffrenet views.

I hope the question is clear and looking foward to see the answers.

Many thanks in advance

  • 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-27T06:15:11+00:00Added an answer on May 27, 2026 at 6:15 am

    Let’s supose that for each day you should apply lowest price.

    create function price ( @fromDate date, @toDate date) returns money
    as
    begin
     declare @iterator_day date
     declare @total money
     set @total = 0
     set @iterator_day = @fromDate
     WHILE @iterator_day < = @toDate
     begin
        select @total = @total + min( price )
        from offers
        where @iterator_day  between offers.fromFay and offers.toDay
        set @iterator_day = DATEADD (day , 1 , @iterator_day )
     end
     return @total
    end
    

    then you can call function in your query:

    select 
       b.fromDay, b.toDay, dbo.price( b.fromDay, b.toDay )
    from 
       booking b
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two projects in my Solution. One implements my business logic and has
The company I work for is looking to implement a caching solution. We have
for a programming assignment I have been asked to implement a solution to the
I've tried two different methods of reusing code. I have a solution full of
I have one date, let's say '2010-12-20' of a flight departure, and two times,
I have these two options to implement a design, that are both extremely 'ugly'
I am trying to implement a forgotten password solution in rails. I have a
I need to have a TabHost consisting of two tabs where each tab represented
I implement in my gallery a tabbing system, I have two tabs gallery1 and
I have asked two questions earlier about this and for each post there was

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.