How can I check if two different date objects have the same date information(having same day, month, year ...)? I have tried "==", "===" and .equals but none seems to work.
There are two ways to check if two dates are equal in Java : Date's equals() method - return true if two dates are equal. Date's compareTo() method - return zero if two dates are equal.
datepicker({ numberOfMonths: 2, onSelect: function(selected) { $("#txtToDate"). datepicker("option", "minDate", selected) } }); $("#txtToDate"). datepicker({ numberOfMonths: 2, onSelect: function(selected) { $("#txtFromDate"). datepicker("option", "maxDate", selected) } }); });
Here we will see, SQL Query to compare two dates. This can be easily done using equals to(=), less than(<), and greater than(>) operators. In SQL, the date value has DATE datatype which accepts date in 'yyyy-mm-dd' format. To compare two dates, we will declare two dates and compare them using the IF-ELSE statement.
You can use valueOf()
or getTime()
:
a = new Date(1995,11,17); b = new Date(1995,11,17); a.getTime() === b.getTime() // prints true
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With