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
            Asked
            
        
        
            Active
            
        
            Viewed 52 times
        
    0
            
            
         
    
    
        bramhaag
        
- 135
- 1
- 1
- 18
- 
                    3Have a look: http://stackoverflow.com/questions/492994/compare-dates-with-javascript – Jude Dec 20 '14 at 09:26
- 
                    1see this http://stackoverflow.com/questions/23443310/compare-two-date-using-javascript something like you want – nikita Dec 20 '14 at 09:29
- 
                    Yes, you have to look above like. It will for you. – Manoj Sharma Dec 20 '14 at 09:29
1 Answers
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