I have two date time strings formated like so; 29/09/2009 15:19 & 29/09/2009 17:19 and basiclly all i want to do is compare the two date and time to see which is greater
Any Help?
When we think of date comparison in JavaScript, we think of using the Date object ( Date() ) and, of course, it works. The date object allows us to perform comparisons using the > , < , = , or >= comparison operators, but not the equality comparison operators like == , != , === , and !==
The Date object is a built-in object in JavaScript that stores the date and time. It provides a number of built-in methods for formatting and managing that data. By default, a new Date instance without arguments provided creates an object corresponding to the current date and time.
In Java, two dates can be compared using the compareTo() method of Comparable interface. This method returns '0' if both the dates are equal, it returns a value "greater than 0" if date1 is after date2 and it returns a value "less than 0" if date1 is before date2.
if ( Date.parse ( firstDateString ) > Date.parse ( secondDateString ) ) {
// first date is greater
}
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