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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T08:52:06+00:00 2026-05-12T08:52:06+00:00

I have 2 JQuery Date fields Arrival Departure Arrival date must not be todays

  • 0

I have 2 JQuery Date fields

  1. Arrival
  2. Departure

Arrival date must not be todays date – i got this sorted using minDate: 1 in the javascript

The Departure date must always be a minimum of 2 days ahead of arrival date. i thought minDate: 3 would work but thats querying off of todays date. it works fine if the user picks tomorrows date in the arrival field but if the user picks an arrival date in the future it breaks. I need the departure date to reference the arrival date and move it 2 days ahead as the minimum date the user can pick, essentially when booking this hotel the user can not stay for one night, 2 night min is required.

finally i also need to calculate the number of nights between the arrival date and departure date into a 3rd text field. so when the departure date is entered it automatically inputs number of nights in 3rd text field. I also need it to work in reverse, if a user decides to put in number of nights i need the departure date to change accordingly.

  • 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-12T08:52:06+00:00Added an answer on May 12, 2026 at 8:52 am

    I’m sure this example isn’t perfect, but here’s a working demo with most of what you require, using just jQuery and the jQuery UI Datepicker:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
    <head>
        <meta http-equiv="Content-type" content="text/html; charset=UTF-8" />
        <title>Datepicker &amp; Difference</title>
        <link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7/themes/redmond/jquery-ui.css" media="screen" />
        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"></script>
        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7/jquery-ui.min.js"></script>
        <script type="text/javascript">
            var DatePicked = function() {
                var departure = $("#departure");
                var arrival = $("#arrival");
                var nights = $("#nights");
    
                var triggeringElement = $(this);
    
                var departureDate = departure.datepicker("getDate");
    
                var minArrivalDate = new Date();
                if (departureDate != null) {
                    minArrivalDate.setDate(departureDate.getDate() + 2);
                } else {
                    minArrivalDate.setDate(minArrivalDate.getDate() + 1);
                }
                arrival.datepicker('option', 'minDate', minArrivalDate);
    
                var arrivalDate = arrival.datepicker("getDate");
    
                if (departureDate != null && arrivalDate != null && triggeringElement.attr("id") != "nights") {
                    var oneDay = 1000*60*60*24;
                    var difference = Math.ceil((arrivalDate.getTime() - departureDate.getTime()) / oneDay);
                    nights.val(difference);
                } else if (departureDate != null && triggeringElement.attr("id") == "nights") {
                    var nightsEntered = parseInt(nights.val());
                    if (nightsEntered >= 2) {
                        var newArrivalDate = new Date();
                        newArrivalDate.setDate(departureDate.getDate() + nightsEntered);
                        arrival.datepicker("setDate", newArrivalDate);
                    } else {
                        alert("Nights must be greater than 2.");
                    }
                }
            }
            $(function() {
                $("#departure, #arrival").datepicker({
                    onSelect: DatePicked
                });
                $("#nights").change(DatePicked);
                DatePicked();
            });
        </script>
    </head>
    <body>
    <div>
        <label for="departure">Departure</label>
        <input type="text" id="departure" name="departure" />
    </div>
    <div>
        <label for="arrival">Arrival</label>
        <input type="text" id="arrival" name="arrival" />
    </div>
    <div>
        <label for="nights">Nights</label>
        <input type="text" id="nights" name="nights" />
    </div>
    </body>
    </html>
    

    Play around with that and see if you can integrate something similar into your app/site.

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

Sidebar

Related Questions

I have a pair of date fields, from and to, and am using jQuery
I'm using the jQuery datepicker where I have two textboxes (start date / end
I have a div class='messages'. I add date to this div via jQuery.append() Here
I have a long list of items with date fields. Allowing jQuery to assign
I am using kelvin lucks jquery date picker . I have a start and
I have embedded the fullcalendar jquery control by using this code: $(document).ready(function() { var
I am using jQuery datepicker, I have two datepicker input fields, like following: <html>
I have this jQuery script: // sorting the names of the fields we're hiding
I'm using custom plugin for jQuery UI datepicker - Timepicker I have two fields,
I'm currently working with jQuery and using the datepicker. I have two input fields:

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.