Jquery obtains the number of days in two dates

Source: Internet
Author: User

[Java]
Date. prototype. format = function (){
Var s = '';
S + = this. getFullYear () + '-'; // obtain the year.
S + = (this. getMonth () + 1) + "-"; // obtain the month.
S + = this. getDate (); // get the day.
Return (s); // return the date.
};

Function getAll (){
Var begin = $ (": input [name = from]"). val ();
Var end = $ (": input [name = to]"). val ();
Var AB = begin. split ("-");
Var AE = end. split ("-");
Var db = new Date ();
Db. setUTCFullYear (AB [0], AB [1]-1, AB [2]);
Var de = new Date ();
De. setUTCFullYear (AE [0], AE [1]-1, AE [2]);
Var unixDb = db. getTime ();
Var unixDe = de. getTime ();
Var n = 1;
For (var k = unixDb; k <unixDe ;){
// Alert (new Date (parseInt (k). format (); // The yyyy-MM-dd format of the current day
If (n> 30 ){
Ext. Msg. alert ("prompt", "check-in date is greater than 30 days, cannot be reserved ");
Return false;
}
N = n + 1;
K = k + 24*60*60*1000;
}
}

 

My requirement is that the number of days between two dates cannot be greater than 30. The last day is not calculated. This algorithm is between two dates, but does not include the start and end dates. So I accumulate from 1.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.