Javascript Date Issue Between Browsers

The format the function receives the two dates is: YYYY/MM/DDTHH:MM


encase its unclear

function compareDates(start, end) {
    console.log("Start: " + start);
    console.log("END : " + end);

    var start1 = start.replace(/\T/g,' ')
    var start2 = new Date(start1);

    var end1 = end.replace(/\T/g,' ')
    var end2 = new Date(end1);

    console.log("Str 1: " + start1);
    console.log("Str 2: " + start2);    
    console.log("END 1: " + end1);
    console.log("END 2: " + end2);

    console.log((end - start));
    console.log((end - start) < 0);

    if ((end - start) < 0 || (end - start) == 0) {return false;}else{return true}

Orginal code before debugging

function compareDates(start, end) {
    start = new Date(start.replace(/\T/g,' '));
    end = new Date(end.replace(/\T/g,' '));
    if ((end - start) < 0 || (end - start) == 0) {return false;}else{return true}

The consoles are there for my error logging, in chrome this works fine with no errors and returns false if the end date is equal to or before my start date.

If I run in web-works, i get the following output problems Str 2: Invalid Date END 2: Invalid Date

What I don't understand is why this doesn't work in blackberry web-works but does in chrome and how do I solve this ?




In your regex, have you tried removing the '\' before the 'T'?

You only need to use a leading-slash in that way if the character following it has special meaning to the regex engine (a capital T does not). It looks like Chrome is being lenient and ignoring the slash whereas the other browser is not.


Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.