[FX.php List] [OFF] Javascript question--comparing dates
Bob Patin
bob at patin.com
Thu Dec 4 08:58:00 MST 2014
Hi,
I did see it, and I tried that as well; I tried changing the dates to milliseconds, thinking that would allow me to do comparisons, since I read somewhere that you can’t use == to compare 2 dates.
Just now, thinking I’d waste yet more time on it, I tried this:
var date1 = new Date();
var date2 = new Date("12/04/2014");
var res = compareDates(date1,date2);
alert(res);
and the compareDates function is this:
function compareDates(date1, date2){
date1 = date1.getMilliseconds();
date2 = date2.getMilliseconds();
alert (date1 + “---" + date2);
if (date1 < date2){
return 0;
}else if (date1 == date2){
return 1;
}else if (date1 > date2){
return 2;
}else{
return "UNSOLVED";
}
}
When I run it, the alert gives me a value for date1 but not for date2.
Why am I not getting a value from date2? Can I not use the format that I’m using in the call to the function?
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
> On Dec 4, 2014, at 9:18 AM, Fitzgerald, Theodore C <ted-fitzgerald at uiowa.edu> wrote:
>
> Not sure if you missed my post, so here it is again:
>
> 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/ <http://jsfiddle.net/qpvugLna/1/> (warning, it does show the alert when you visit the page)
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.iviking.org/pipermail/fx.php_list/attachments/20141204/82a6a201/attachment-0001.html
More information about the FX.php_List
mailing list