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

Fitzgerald, Theodore C ted-fitzgerald at uiowa.edu
Wed Dec 3 13:13:53 MST 2014


In order to do the greater than and less than comparison you'll need to be working with Date objects, so if getToday() doesn't return a date object, your function won't work correctly.

I'm not sure what "getToday();" is doing, but to get today's date,  you only need to do "new Date()";.  Here is an example of it working:

http://jsfiddle.net/qpvugLna/1/ (warning, it does show the alert when you visit the page)

Ted

Application Developer
ITS-Enterprise Services
2800 UCC
University of Iowa

-----Original Message-----
From: fx.php_list-bounces at mail.iviking.org [mailto:fx.php_list-bounces at mail.iviking.org] On Behalf Of Bob Patin
Sent: Wednesday, December 03, 2014 1:18 PM
To: FX.php Discussion List
Subject: [FX.php List] [OFF] Javascript question--comparing dates

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

 
 _______________________________________________
FX.php_List mailing list
FX.php_List at mail.iviking.org
http://www.iviking.org/mailman/listinfo/fx.php_list


More information about the FX.php_List mailing list