简体   繁体   English

如何获取两个日期之间选择的总天数?

[英]How do I grab total number of days selected between two dates?

I have this jquery script that allows a user to choose a start date and end date: 我有这个jquery脚本,它允许用户选择开始日期和结束日期:

<script type="text/javascript" charset="utf-8">
    $(document).ready(function () {

        $('#txtToDate').datepicker({ showOn: 'button',
            buttonImage: 'images/20/calendar200.gif',
            buttonImageOnly: true, onSelect: function () { },
            onClose: function () { $(this).focus(); }
        });


        $('#txtFromDate').datepicker({ showOn: 'button',
            buttonImage: 'images/20/calendar200.gif',
            buttonImageOnly: true, onSelect:
        function (dateText, inst) {
            $('#txtToDate').datepicker("option", 'minDate', new Date(dateText));
        }
      ,
            onClose: function () { $(this).focus(); }
        });
        $('#txtToDate').datepicker({
       // Your other options here
        onSelect: function(dateText, inst) {
        var days = ($("#txtToDate").datepicker('getDate') - 
            $("#txtFromDate").datepicker('getDate'))/(24*60*60*1000);
        $('#numOfDays').val(days);
       console.log(days);
    }
  }
  );  

    });  
</script>

Then I have a textbox control: 然后我有一个文本框控件:

<asp:TextBox ID="numOfDays" class="fptextbox12" runat="server" style="width:60px;"></asp:TextBox>

Once a user chooses a start date and an end date, we would like the total number of days in that box. 用户选择开始日期和结束日期后,我们希望在此框中输入总天数。

Any ideas how to calculate this? 任何想法如何计算呢?

Add the onSelect option to the datepicker and calculate the number of days. onSelect选项添加到日期选择器,然后计算天数。

$('#txtToDate').datepicker({
        // Your other options here
        onSelect: function(dateText, inst) {
            var days = ($("#txtToDate").datepicker('getDate') - 
                $("#txtFromDate").datepicker('getDate'))/(24*60*60*1000);
            $('#numOfDays').val(days);
        }
    }
);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何显示从Zebra Datepicker中选择的两个日期中选择的天数? - How do I display the number of days selected from two dates selected from Zebra Datepicker? 如何使用JavaScript返回两个日期之间的假日天数(假日除外)? - How do i use javascript to return the number of days holidays between two dates excluding holidays? 如何获得两个日期之间的天数? - How to get the number of days between two dates? 使用Bootstrap Datepicker选择两个日期时,显示总天数(星期六和星期天除外) - Display total number of days(excluding saturdays and sundays), when two dates are selected using Bootstrap Datepicker jQuery,HTML,如何获取两个日期之间的天数并将其发布 - jQuery, HTML, how to get the number of days between two dates and post it 计算两个日期之间的天数差 - Calculate the difference between two dates in number of days 用momentjs计算两个日期之间的天数 - Calculate number of days between two dates with momentsjs 使用javascript计算两个日期之间的天数 - Count number of days between two dates with javascript 计算两个日期之间的条目总数 - Calculating total number of entries between two dates 计算两个日期之间的天数,并且日期由jquery中的pickadate选择 - calculate number of days between two dates and dates are selecting by pickadate in jquery
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM