[FX.php List] [OFF] Javascript question--comparing dates

Bob Patin bob at patin.com
Wed Dec 3 12:18:08 MST 2014


OK, list, this should be really easy, but I can’t get the proper results:

I have this code:

var date1 = getToday();
var date2 = new Date("12/01/2014");
var res = compareDates(date1,date2);
alert(res);

Here’s the function:

// compare any 2 dates
	// 0 -- date1 < date2
	// 1 -- dates are equal
	// 2 -- date1 > date2

function compareDates(date1, date2){
	if (+date1 < +date2){
		return 0;
	}else if (+date1 == +date2){
		return 1;
	}else if (+date1 > +date2){
		return 2;
	}else{
		return "UNSOLVED";
	}
} 

If you try this, you’ll get UNSOLVED rather than the right answer, which should be 2, because date1 > date2 in my example.

This is so easy to do in PHP, but for some reason, despite lots of Googling, I haven’t gotten anything that works.

Thanks for any enlightenment,

Bob Patin
Longterm Solutions
bob at longtermsolutions.com
615-333-6858
FileMaker 9, 10, 11, 12 & 13 Certified Developer
http://www.longtermsolutions.com
-
iChat: bobpatin at me.com
Twitter: bobpatin
—
FileMaker Consulting 
FileMaker Hosting for all versions of FileMaker
PHP • Full email services • Free DNS hosting • Colocation • Consulting

 
 


More information about the FX.php_List mailing list