views:

24

answers:

1

Hi, Im using date.js to compare to dates that are written in user friendly string form(Sat, 1 July 2006 12:34:14). I use this code.

function is_new(lasttime, newtime){
    lasttime = Date.parse(lastime);
    newtime = Date.parse(newtime);
    if(lasttime.isBefore(newtime)){
        return true;
    }else{
        return false;
    }
}

Both lasttime and newtime are strings like above. When I try this i get

Uncaught TypeError: Object Tue Dec 30 1997 00:00:00 GMT+0000 (GMT Standard Time) has no method 'isBefore'
A: 

There's no function named isBefore. Instead, compare the timestamps:

function is_new(LastTime,NewTime){
  return new Date(LastTime).getTime()<new Date(NewTime).getTime();
}

alert(is_new("Dec 30, 1997","Dec 31, 1997"));
Gert G
http://code.google.com/p/datejs/wiki/APIDocumentation#isBefore
theIV
I see... `datejs`... Then the question is if the library has been loaded or not.
Gert G
I got it later with get_time() but thanks anyway. Accepted
Neb
Thanks. I'm glad you got it working.
Gert G
As far as I can work out, the `isBefore()` function was added in `2008-04-25` while the build date of the downloadable `date.js` file is `Nov 2007`. So `isBefore()` is in there somewhere, but you'll have to add it yourself. I'm trying to get this to work now, and it's frustrating me.
TRiG
See http://stackoverflow.com/questions/2434329/datejs-parsing-mystery/2436231#2436231 for a fix.
TRiG