Monday, June 17, 2013

Compare two time in javascript

Below is the function used to compare the two time using java scipt.

function checkTime(startTime, endTime) {
//compare two times are same or not....
if (Date.parse('17/06/2013 ' + endTime) - Date.parse('17/06/2013 ' + startTime) == 0) {
        alert('Both time cannot be same');
        return false;
   else if (Date.parse('17/06/2013 ' + endTime) < Date.parse('17/06/2013 ' + startTime)) {
        alert('End time should be greater then Start time');
        return false;
    return true;

This function returns true if end time is greater than the start time. Otherwise it return false.
Instead of  '17/06/201' you can use any date. 

No comments:

Post a Comment