Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jquery date comparison

Hi iam using the following code for comparing the entered date with current date... But it is not working...

$('#<%=txtOrderDate.ClientID%>').change(function() {
            var date = $('#<%=txtOrderDate.ClientID%>').val();
            var arrDate = date.split("/");
            var today = new Date();
            var useDate = new Date(arrDate[2], arrDate[1] - 1, arrDate[0]);
            if (useDate > today) {
                alert('Please Enter the correctDate');
                $('#<%=txtOrderDate.ClientID%>').val('');
            }
        });

Help me if anybody knows it... Advance thanks....

like image 383
Nithesh Narayanan Avatar asked Sep 29 '26 15:09

Nithesh Narayanan


1 Answers

i tried to copy your code and this works on my machine

            $('#txtbox').change(function() {
                var date = $(this).val();
                var arrDate = date.split("/");
                var today = new Date();
                useDate = new Date(arrDate[2], arrDate[1] -1, arrDate[0]);

                if (useDate > today) {
                    alert('Please Enter the correctDate');
                    $(this).val('');
                }
            });

i removed the var from the useDate, and take note that new Dateparameter is (y,m,d).

like image 157
hallie Avatar answered Oct 01 '26 05:10

hallie



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!