0

I have a question for you guys. I want to compare the date of today and an other self made date. The date of today is called a and the name of the self made date is b. If ais later then b I want to do something, but how. And the date format should be year,month,day,hour,minute,second e.g: 2015,03,20,09,58,44

bramhaag
  • 135
  • 1
  • 1
  • 18

1 Answers1

0
// First date is older

var a = new Date(2015,03,20,09,58,44).valueOf(),
b = new Date(2015,04,20,09,58,44).valueOf();

console.log((a > b), (a < b), (a === b)); // false, true, false

// Second date is older

var c = new Date(2015,03,20,09,58,44).valueOf(),
d = new Date(2015,02,20,09,58,44).valueOf();

console.log((c > d), (c < d), (c === d)); // true, false, false

// Same date

var now = new Date().valueOf(),
now2 = new Date().valueOf();

console.log((now > now2), (now < now2), (now === now2)); // false, false, true

// As a function

function isLater(a, b) {
    a = a.valueOf();
    b = b.valueOf();

    if (a > b) {
        return true;
    } else if (a < b) {
        return false;
    } else if (a === b) {
        // edge case
    }
}
Makaze
  • 1,076
  • 7
  • 13