Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Checking if two Dates have the same date info

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.

like image 696
Hellnar Avatar asked Dec 13 '10 11:12

Hellnar


People also ask

How do you find out if two dates are the same?

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.

How do I compare two dates in Datepicker?

datepicker({ numberOfMonths: 2, onSelect: function(selected) { $("#txtToDate"). datepicker("option", "minDate", selected) } }); $("#txtToDate"). datepicker({ numberOfMonths: 2, onSelect: function(selected) { $("#txtFromDate"). datepicker("option", "maxDate", selected) } }); });

How can I compare two dates in SQL query?

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.


1 Answers

You can use valueOf() or getTime():

a = new Date(1995,11,17); b = new Date(1995,11,17);  a.getTime() === b.getTime() // prints true 
like image 65
Felix Kling Avatar answered Oct 14 '22 14:10

Felix Kling