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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T00:21:34+00:00 2026-05-31T00:21:34+00:00

I have a question about javascript time ranges i have two input boxes, the

  • 0

I have a question about javascript time ranges

i have two input boxes, the client can give start date and end date

below have 3 seasons with date ranges,i need to count the cost for the user entered date range with
the mapping with below seasons with prices

Total is 3 seasons, below is the date ranges:

Low Season

1st May to 30th June
1st September to 14th December

Cost: $5 per day


High Season

11th January to 30th April
1st July to 31st August

Cost: $10 per day


Peak Season

-15th December – 10th January
Cost: $2 per day

i write a code for get the date inputs

$('#calculate').click(function(){
//get the first date
da=$('#daydropdowna').val();
ma=$('#monthdropdowna').val();
ya=$('#yeardropdowna').val();



//get the secnd date
dd=$('#daydropdownd').val();
md=$('#monthdropdownd').val();
yd=$('#yeardropdownd').val();



var oneDay = 24*60*60*1000; 
var ourstart= new Date(ya,ma,da);
var oursend= new Date(yd,md,dd);


/*
11th January to 30th April 
1st July to 31st August 
*/
var hsstart= new Date(ya,00,11);
var hsend= new Date(ya,03,11);
var hsstart1= new Date(ya,06,01);
var hsend1= new Date(ya,07,31);


/*
1st May to 30th June 
1st September to 14th December 
*/

var lsstart=new Date(ya,04,01);
var lsend=new Date(ya,05,30);
var lsstart1=Date(ya,08,01);
var lsend1=new Date(ya,11,14);


/*
-15th December - 10th January 
*/
var psstart=new Date(ya,11,15);
var psend=new Date(ya+1,00,10);


var myDate = ourstart;
var myDate1 = oursend;




var startDate = hsstart
var endDate = hsend



//the date range within one high season

if ((startDate < myDate) && (myDate < endDate) && (startDate < myDate1) && (myDate1 < endDate)) {
        alert('seasn 1 h');
       var diffDays = Math.round(Math.abs((myDate1 .getTime() - myDate .getTime())/(oneDay)));

alert (diffDays);
}


//the date range within secnd high season
var startDate = hsstart1
var endDate = hsend1

if ((startDate < myDate) && (myDate < endDate) && (startDate < myDate1) && (myDate1 < endDate)) {
        alert('seasn 2 h');
       var diffDays = Math.round(Math.abs((myDate1 .getTime() - myDate .getTime())/(oneDay)));

alert (diffDays);
}


//the date range within first low season
var startDate = lsstart
var endDate = lsend

if ((startDate < myDate) && (myDate < endDate) && (startDate < myDate1) && (myDate1 < endDate)) {
        alert('season 1 l');
       var diffDays = Math.round(Math.abs((myDate1 .getTime() - myDate .getTime())/(oneDay)));

alert (diffDays);
}



//the date range within second low season
var startDate = lsstart1
var endDate = lsend1



if ((startDate < myDate) && (myDate < endDate) && (startDate < myDate1) && (myDate1 < endDate)) {
        alert('season 2 l');
       var diffDays = Math.round(Math.abs((myDate1 .getTime() - myDate .getTime())/(oneDay)));

alert (diffDays);
}

//peak
var startDate = psstart
var endDate = psend

if ((startDate < myDate) && (myDate < endDate) && (startDate < myDate1) && (myDate1 < endDate)) {
        alert('season p');
       var diffDays = Math.round(Math.abs((myDate1 .getTime() - myDate .getTime())/(oneDay)));

alert (diffDays);
}


//if not wihin a specific range cacuate for all











});

so i need to calculate the total price according to the user input, Ex user enters 2012-05-05 – 2013-01-05 this need to calculate price for 3 season dates which is covering the date range. please hep me for solve this problem, thank you…

  • 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-31T00:21:36+00:00Added an answer on May 31, 2026 at 12:21 am

    I’m not going to code for you but here’s the logic:

    tempDate = inputStartDate
    for each season
        if seasonStart <= tempDate
            if inputEndDate <= seasonEnd
                price = price + (inputEndDate - tempDate) * seasonCost
                break
            else
                price = price + (seasonEnd - tempDate) * seasonCost
                tempDate = seasonEnd + 1 day
    

    price will contain the total cost/day for the entire date range.

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

Sidebar

Related Questions

I am making a webapp. I have a fairly basic question about javascript performance.
I have a question about reloading JavaScript files. I develop web pages front-ends and
There have been some questions about whether or not JavaScript is an object-oriented language.
I have question about NSView: Imagine a Custom View where the mouseDown, mouseDrag and
I have question about normalization. Suppose I have an applications dealing with songs. First
I have a question about using streams in .NET to load files from disk.
I have a question about best practices regarding how one should approach storing complex
I have a question about locking. This doesn't have to be only about record
I have a question about how to deploy WPF application into a PC without
I have a question about using os.execvp in Python. I have the following bit

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.