Wednesday, October 14, 2015

Compare Time using Javascript

Some time we need to compare two time for our development. In  JS it is difficult. In this topics I discus on how to compare two time. For this I create a JS function named timecompare. Here we passed tow parameter for this function named startTime and endTime. This function return TRUE only when second parameter (time) larger then first one

function timecompare(startTime,endTime){
    var regExp = /(\d{1,2})\:(\d{1,2})\:(\d{1,2})/;
    if(parseInt(endTime .replace(regExp, "$1$2$3")) > parseInt(startTime .replace(regExp, "$1$2$3"))){
    return true;
        return false;
timecompare('14:01:20','22:00:00'); // Output : TRUE
timecompare('10:01:20','2:00:00'); // Output : FALSE


  1. Hi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me.. I am a regular follower of your blog. Really very informative post you shared here.
    Kindly keep blogging. If anyone wants to become a Front end developer learn from javascript and jquery training in chennai .
    or learn thru Javascript Training in Chennai.
    Nowadays JavaScript has tons of job opportunities on various vertical industry. javascript and jquery training in chennai



Copyright @ 2014 Tech Tutorial .