E
E
EVOSandru62015-10-30 11:59:35
JavaScript
EVOSandru6, 2015-10-30 11:59:35

How in js / jquery to compare the strings "date time" for more - less?

There is a line like :
var str = '30.10.2015 19:53';
In php, I compare such things by translating into a timestamp:

$stamp1 = My::getTimeStamp(str);

static function getTimeStamp($dateFormat)
    {

        $dateTime   =   explode(' ',$dateFormat);
        $date       =   $dateTime[0];
        $time       =   $dateTime[1];
        $dMY        =   explode('.',$date);
        $hm         =   explode(':',$time);
        $day        =   $dMY[0];
        $month      =   $dMY[1];
        $year       =   $dMY[2];
        $hour       =   $hm[0];
        $minutes    =   $hm[1];
        return mktime($hour, $minutes, 0, $month, $day, $year);
    }

I have 2 such strings and I need to compare them on the client, please help!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrew, 2015-10-30
@EVOSandru6

var date1 = new Date();
var date2 = new Date('30.10.2015 19:53');

And compare
date1 > date2

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question