Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Maung-C's avatar

Datetimepicker Date different

I want to date difference between using datetimepicker not datepicker .how cant i get and i try but it's show " NaN " . below my javascript

        $('#myModal').on('show.bs.modal', function (event) {
            var button = $(event.relatedTarget)
            var fromDate = button.data('fromdate')
            var toDate = button.data('todate')

            var from = $('#fromDate').val();

                var to = $('#toDate').val();
                var diff = Date(to - from);
                var days = diff/1000/60/60/24;
                
            console.log(days)
    )};
 
0 likes
1 reply
Snapey's avatar

Those input fields will be returned as strings, but you are trying to do math on them

You need to parse them with something like moment.js so that you can then do the math operations

https://momentjs.com/

Please or to participate in this conversation.