开发者

jquery datepicker, dates range count

开发者 https://www.devze.com 2022-12-17 19:18 出处:网络
i am trying to sum up or deduct dates in selected range using jquery datepicker, here is how i am doing it right now but without any luck.

i am trying to sum up or deduct dates in selected range using jquery datepicker, here is how i am doing it right now but without any luck.

function test(){
    var sundayCheck = 0;
    var saturdayCheck = 0;
    var totalDays = 0;

    sundayCheck = new Date($("#onlySunday").datepicker("getDate"));
    saturdayCheck = new Date($("#onlySaturday").datepicker("getDate"));

    totalDays = saturdayCheck.getDate() - sundayCheck.getDate();

    alert(totalDays);
}开发者_如何转开发

thats a piece of code that should make calculation but what it does is just deducts days like,

24.01.10 - 06.02.10 = -18 which is totaly wrong as it should be more days its just does not consider the days and its just using first numbers of dates.

If anyone could help how to make such calculations i would appreciate the most.


Are you trying to dtermine the number of days between two dates?

  totalDays = Math.ceil((saturdayCheck.getTime()-sundayCheck.getTime())/(1000*60*60*24);

First get the number of milliseconds between the two dates then divide by the number of milliseconds in a day. Using Math.ceil to round up to nearest integer.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号