From bob at patin.com Wed Dec 3 12:18:08 2014 From: bob at patin.com (Bob Patin) Date: Wed Dec 3 12:13:06 2014 Subject: [FX.php List] [OFF] Javascript question--comparing dates Message-ID: <6505D799-A52C-4FD1-B8F1-E2587F3640B5@patin.com> 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@longtermsolutions.com 615-333-6858 FileMaker 9, 10, 11, 12 & 13 Certified Developer http://www.longtermsolutions.com - iChat: bobpatin@me.com Twitter: bobpatin ? FileMaker Consulting FileMaker Hosting for all versions of FileMaker PHP ? Full email services ? Free DNS hosting ? Colocation ? Consulting From dness at bondedbuilders.com Wed Dec 3 12:53:07 2014 From: dness at bondedbuilders.com (Ness, David) Date: Wed Dec 3 12:47:52 2014 Subject: [FX.php List] [OFF] Javascript question--comparing dates In-Reply-To: <6505D799-A52C-4FD1-B8F1-E2587F3640B5@patin.com> References: <6505D799-A52C-4FD1-B8F1-E2587F3640B5@patin.com> Message-ID: Bob, Since getToday() isn't a JavaScript function, I assume it's a custom function? David Ness FileMaker & Web Applications Developer Bonded Builders Warranty Group St. Petersburg, Florida USA 800-749-0381 x4923 -----Original Message----- From: fx.php_list-bounces@mail.iviking.org [mailto:fx.php_list-bounces@mail.iviking.org] On Behalf Of Bob Patin Sent: Wednesday, December 03, 2014 2: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@longtermsolutions.com 615-333-6858 FileMaker 9, 10, 11, 12 & 13 Certified Developer http://www.longtermsolutions.com - iChat: bobpatin@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@mail.iviking.org http://www.iviking.org/mailman/listinfo/fx.php_list From dness at bondedbuilders.com Wed Dec 3 13:05:39 2014 From: dness at bondedbuilders.com (Ness, David) Date: Wed Dec 3 13:00:23 2014 Subject: [FX.php List] [OFF] Javascript question--comparing dates In-Reply-To: <6505D799-A52C-4FD1-B8F1-E2587F3640B5@patin.com> References: <6505D799-A52C-4FD1-B8F1-E2587F3640B5@patin.com> Message-ID: Bob, This is what I use to compare dates. Hope this helps: ------------------------------------------ function compareDates(value1, value2) { /* A simple function that takes two well formed dates. The function will compare the dates and return: 0 if the dates are same -1 if the first one is an earlier date 1 if the first one is a later date */ var date1, date2; var month1, month2; var year1, year2; month1 = value1.substring (0, value1.indexOf (dtCh)); date1 = value1.substring (value1.indexOf (dtCh)+1, value1.lastIndexOf (dtCh)); year1 = value1.substring (value1.lastIndexOf (dtCh)+1, value1.length); month2 = value2.substring (0, value2.indexOf (dtCh)); date2 = value2.substring (value2.indexOf (dtCh)+1, value2.lastIndexOf (dtCh)); year2 = value2.substring (value2.lastIndexOf (dtCh)+1, value2.length); if(month1.length == 1) {month1 = '0' + month1} if(date1.length == 1) {date1 = '0' + date1} if(month2.length == 1) {month2 = '0' + month2} if(date2.length == 1) {date2 = '0' + date2} if (year1 > year2) return 1; else if (year1 < year2) return -1; else if (month1 > month2) return 1; else if (month1 < month2) return -1; else if (date1 > date2) return 1; else if (date1 < date2) return -1; else return 0; } // example on calling the function isDate() function ValidateDate(){ var dt=document.frmSample.txtDate if (isDate(dt.value)==false){ dt.focus() return false } return true } -------------------------------------------- David Ness FileMaker & Web Applications Developer Bonded Builders Warranty Group St. Petersburg, Florida USA 800-749-0381 x4923 -----Original Message----- From: fx.php_list-bounces@mail.iviking.org [mailto:fx.php_list-bounces@mail.iviking.org] On Behalf Of Bob Patin Sent: Wednesday, December 03, 2014 2: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@longtermsolutions.com 615-333-6858 FileMaker 9, 10, 11, 12 & 13 Certified Developer http://www.longtermsolutions.com - iChat: bobpatin@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@mail.iviking.org http://www.iviking.org/mailman/listinfo/fx.php_list From dness at bondedbuilders.com Wed Dec 3 13:12:40 2014 From: dness at bondedbuilders.com (Ness, David) Date: Wed Dec 3 13:07:23 2014 Subject: [FX.php List] [OFF] Javascript question--comparing dates In-Reply-To: References: <6505D799-A52C-4FD1-B8F1-E2587F3640B5@patin.com> Message-ID: <220fc5c5dbf84771acc697755af0505c@BLUPR02MB439.namprd02.prod.outlook.com> Bob, Ignore the second function " ValidateDate()" accidentally included. It requires another custom JavaScript function, although I'd be happy to provide it to you if you have a need for "isDate()". David Ness FileMaker & Web Applications Developer Bonded Builders Warranty Group St. Petersburg, Florida USA 800-749-0381 x4923 -----Original Message----- From: fx.php_list-bounces@mail.iviking.org [mailto:fx.php_list-bounces@mail.iviking.org] On Behalf Of Ness, David Sent: Wednesday, December 03, 2014 3:06 PM To: FX.php Discussion List Subject: RE: [FX.php List] [OFF] Javascript question--comparing dates Bob, This is what I use to compare dates. Hope this helps: ------------------------------------------ function compareDates(value1, value2) { /* A simple function that takes two well formed dates. The function will compare the dates and return: 0 if the dates are same -1 if the first one is an earlier date 1 if the first one is a later date */ var date1, date2; var month1, month2; var year1, year2; month1 = value1.substring (0, value1.indexOf (dtCh)); date1 = value1.substring (value1.indexOf (dtCh)+1, value1.lastIndexOf (dtCh)); year1 = value1.substring (value1.lastIndexOf (dtCh)+1, value1.length); month2 = value2.substring (0, value2.indexOf (dtCh)); date2 = value2.substring (value2.indexOf (dtCh)+1, value2.lastIndexOf (dtCh)); year2 = value2.substring (value2.lastIndexOf (dtCh)+1, value2.length); if(month1.length == 1) {month1 = '0' + month1} if(date1.length == 1) {date1 = '0' + date1} if(month2.length == 1) {month2 = '0' + month2} if(date2.length == 1) {date2 = '0' + date2} if (year1 > year2) return 1; else if (year1 < year2) return -1; else if (month1 > month2) return 1; else if (month1 < month2) return -1; else if (date1 > date2) return 1; else if (date1 < date2) return -1; else return 0; } // Ignore the code below. // example on calling the function isDate() function ValidateDate(){ var dt=document.frmSample.txtDate if (isDate(dt.value)==false){ dt.focus() return false } return true } -------------------------------------------- David Ness FileMaker & Web Applications Developer Bonded Builders Warranty Group St. Petersburg, Florida USA 800-749-0381 x4923 -----Original Message----- From: fx.php_list-bounces@mail.iviking.org [mailto:fx.php_list-bounces@mail.iviking.org] On Behalf Of Bob Patin Sent: Wednesday, December 03, 2014 2: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@longtermsolutions.com 615-333-6858 FileMaker 9, 10, 11, 12 & 13 Certified Developer http://www.longtermsolutions.com - iChat: bobpatin@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@mail.iviking.org http://www.iviking.org/mailman/listinfo/fx.php_list From ted-fitzgerald at uiowa.edu Wed Dec 3 13:13:53 2014 From: ted-fitzgerald at uiowa.edu (Fitzgerald, Theodore C) Date: Wed Dec 3 13:08:35 2014 Subject: [FX.php List] [OFF] Javascript question--comparing dates In-Reply-To: <6505D799-A52C-4FD1-B8F1-E2587F3640B5@patin.com> References: <6505D799-A52C-4FD1-B8F1-E2587F3640B5@patin.com> Message-ID: 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@mail.iviking.org [mailto:fx.php_list-bounces@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@longtermsolutions.com 615-333-6858 FileMaker 9, 10, 11, 12 & 13 Certified Developer http://www.longtermsolutions.com - iChat: bobpatin@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@mail.iviking.org http://www.iviking.org/mailman/listinfo/fx.php_list From bob at patin.com Thu Dec 4 07:48:42 2014 From: bob at patin.com (Bob Patin) Date: Thu Dec 4 07:43:37 2014 Subject: [FX.php List] [OFF] Javascript question--comparing dates In-Reply-To: References: <6505D799-A52C-4FD1-B8F1-E2587F3640B5@patin.com> Message-ID: It is, but it?s just a simple bit of code. I tried for an hour to get it to work; I tried translating the dates to milliseconds and then doing math comparisons, but I never got it to work. I?m going to work around it by doing it in PHP, but I would have thought that there would be a simple way to do date comparisons in Javascript? oh well. Bob Patin Longterm Solutions bob@longtermsolutions.com 615-333-6858 FileMaker 9, 10, 11, 12 & 13 Certified Developer http://www.longtermsolutions.com - iChat: bobpatin@me.com Twitter: bobpatin ? FileMaker Consulting FileMaker Hosting for all versions of FileMaker PHP ? Full email services ? Free DNS hosting ? Colocation ? Consulting > On Dec 3, 2014, at 1:53 PM, Ness, David wrote: > > Bob, > > Since getToday() isn't a JavaScript function, I assume it's a custom function? -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.iviking.org/pipermail/fx.php_list/attachments/20141204/78c6b303/attachment.html From ted-fitzgerald at uiowa.edu Thu Dec 4 08:18:40 2014 From: ted-fitzgerald at uiowa.edu (Fitzgerald, Theodore C) Date: Thu Dec 4 08:13:18 2014 Subject: [FX.php List] [OFF] Javascript question--comparing dates In-Reply-To: References: <6505D799-A52C-4FD1-B8F1-E2587F3640B5@patin.com> Message-ID: Bob, 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/ (warning, it does show the alert when you visit the page) Ted Application Developer ITS-Enterprise Services 2800 UCC University of Iowa From: fx.php_list-bounces@mail.iviking.org [mailto:fx.php_list-bounces@mail.iviking.org] On Behalf Of Bob Patin Sent: Thursday, December 04, 2014 8:49 AM To: FX.php Discussion List Subject: Re: [FX.php List] [OFF] Javascript question--comparing dates It is, but it?s just a simple bit of code. I tried for an hour to get it to work; I tried translating the dates to milliseconds and then doing math comparisons, but I never got it to work. I?m going to work around it by doing it in PHP, but I would have thought that there would be a simple way to do date comparisons in Javascript? oh well. Bob Patin Longterm Solutions bob@longtermsolutions.com 615-333-6858 FileMaker 9, 10, 11, 12 & 13 Certified Developer http://www.longtermsolutions.com - iChat: bobpatin@me.com Twitter: bobpatin ? FileMaker Consulting FileMaker Hosting for all versions of FileMaker PHP ? Full email services ? Free DNS hosting ? Colocation ? Consulting On Dec 3, 2014, at 1:53 PM, Ness, David > wrote: Bob, Since getToday() isn't a JavaScript function, I assume it's a custom function? -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.iviking.org/pipermail/fx.php_list/attachments/20141204/5652831c/attachment.html From bob at patin.com Thu Dec 4 08:58:00 2014 From: bob at patin.com (Bob Patin) Date: Thu Dec 4 08:52:53 2014 Subject: [FX.php List] [OFF] Javascript question--comparing dates In-Reply-To: References: <6505D799-A52C-4FD1-B8F1-E2587F3640B5@patin.com> Message-ID: 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@longtermsolutions.com 615-333-6858 FileMaker 9, 10, 11, 12 & 13 Certified Developer http://www.longtermsolutions.com - iChat: bobpatin@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 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/ (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 From bob at patin.com Thu Dec 4 08:58:54 2014 From: bob at patin.com (Bob Patin) Date: Thu Dec 4 08:53:47 2014 Subject: [FX.php List] [OFF] Javascript question--comparing dates In-Reply-To: References: <6505D799-A52C-4FD1-B8F1-E2587F3640B5@patin.com> Message-ID: <64FDE1FD-7A2A-436C-86FB-E38504F0D484@patin.com> I also tried this: date2 = new Date(2014,12,4); But that doesn?t work either. > On Dec 4, 2014, at 9:58 AM, Bob Patin wrote: > > 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@longtermsolutions.com > 615-333-6858 > FileMaker 9, 10, 11, 12 & 13 Certified Developer > http://www.longtermsolutions.com > - > iChat: bobpatin@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 > 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/ (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/86229c67/attachment.html From ted-fitzgerald at uiowa.edu Thu Dec 4 09:07:37 2014 From: ted-fitzgerald at uiowa.edu (Fitzgerald, Theodore C) Date: Thu Dec 4 09:02:16 2014 Subject: [FX.php List] [OFF] Javascript question--comparing dates In-Reply-To: <64FDE1FD-7A2A-436C-86FB-E38504F0D484@patin.com> References: <6505D799-A52C-4FD1-B8F1-E2587F3640B5@patin.com> <64FDE1FD-7A2A-436C-86FB-E38504F0D484@patin.com> Message-ID: Bob, Sorry, I didn?t take into account that doing ?date1 = new Date();? also includes the time, while with ?date2 = new Date(?12/04/2014?);? the time is at midnight (I believe), so technically date1 is greater than date2 in this instance. Try this: var date1 = "12/04/2014"; var date2 = new Date("12/04/2014"); var res = compareDates(date1,date2); alert(res); function isDateObject(val) { if (val === null) { return false;} return ( Object.prototype.toString.call(val) === '[object Date]'); } function compareDates(date1, date2){ if (!isDateObject(date1)) { date1 = new Date(date1);} if (!isDateObject(date2)) { date2 = new Date(date2);} if (+date1 < +date2){ return 0; }else if (+date1 == +date2){ return 1; }else if (+date1 > +date2){ return 2; }else{ return "UNSOLVED"; } } Ted Application Developer ITS-Enterprise Services 2800 UCC University of Iowa From: fx.php_list-bounces@mail.iviking.org [mailto:fx.php_list-bounces@mail.iviking.org] On Behalf Of Bob Patin Sent: Thursday, December 04, 2014 9:59 AM To: FX.php Discussion List Subject: Re: [FX.php List] [OFF] Javascript question--comparing dates I also tried this: date2 = new Date(2014,12,4); But that doesn?t work either. On Dec 4, 2014, at 9:58 AM, Bob Patin > wrote: 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@longtermsolutions.com 615-333-6858 FileMaker 9, 10, 11, 12 & 13 Certified Developer http://www.longtermsolutions.com - iChat: bobpatin@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 > 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/ (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/84470739/attachment-0001.html From chris at iViking.org Thu Dec 4 10:33:00 2014 From: chris at iViking.org (Chris Hansen) Date: Thu Dec 4 10:27:39 2014 Subject: [FX.php List] [OFF] Javascript question--comparing dates In-Reply-To: <6505D799-A52C-4FD1-B8F1-E2587F3640B5@patin.com> References: <6505D799-A52C-4FD1-B8F1-E2587F3640B5@patin.com> Message-ID: Hey Bob, A couple thoughts: 1) I know I?ve had trouble in the past some places with a leading zero on the day when using m/d/Y formatting; 2) Not all browsers accept the same date formats as strings when using the Date() constructor; 3) Based on the above, I?d personally pass the year, month, and day separately as integers, rather than a single string. HTH ?-Chris > On Dec 3, 2014, at 12:18 PM, Bob Patin wrote: > > 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@longtermsolutions.com > 615-333-6858 > FileMaker 9, 10, 11, 12 & 13 Certified Developer > http://www.longtermsolutions.com > - > iChat: bobpatin@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@mail.iviking.org > http://www.iviking.org/mailman/listinfo/fx.php_list > From bob at patin.com Thu Dec 4 10:35:39 2014 From: bob at patin.com (Bob Patin) Date: Thu Dec 4 10:30:33 2014 Subject: [FX.php List] [OFF] Javascript question--comparing dates In-Reply-To: References: <6505D799-A52C-4FD1-B8F1-E2587F3640B5@patin.com> Message-ID: Hey Chris, Hope you?re well; I?ll keep #3 in mind for sure. It became a mission at some point to figure out why I couldn?t get such a simple thing working? wasted far too much time putzing with it. Take care, Bob Patin Longterm Solutions bob@longtermsolutions.com 615-333-6858 FileMaker 9, 10, 11, 12 & 13 Certified Developer http://www.longtermsolutions.com - iChat: bobpatin@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 11:33 AM, Chris Hansen wrote: > > > A couple thoughts: > > 1) I know I?ve had trouble in the past some places with a leading zero on the day when using m/d/Y formatting; > > 2) Not all browsers accept the same date formats as strings when using the Date() constructor; > > 3) Based on the above, I?d personally pass the year, month, and day separately as integers, rather than a single string. > > HTH -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.iviking.org/pipermail/fx.php_list/attachments/20141204/332ad29f/attachment.html From art at uic.edu Thu Dec 4 11:31:26 2014 From: art at uic.edu (Anderson, John A.) Date: Thu Dec 4 11:26:04 2014 Subject: [FX.php List] [OFF] Javascript question--comparing dates In-Reply-To: References: <6505D799-A52C-4FD1-B8F1-E2587F3640B5@patin.com> Message-ID: Bob, Try this simple modification to Ted's original function, (add after "var date1 = new Date();" to zero out the time part of the date object), date1.setHours(0,0,0,0); original function: http://jsfiddle.net/qpvugLna/1/ (warning, it does show the alert when you visit the page) modified function: http://jsfiddle.net/5afeLdww/ (ditto warning) Art On Thu, December 4, 2014 9:58 am, Bob Patin wrote: > 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@longtermsolutions.com > 615-333-6858 > FileMaker 9, 10, 11, 12 & 13 Certified Developer > http://www.longtermsolutions.com > - > iChat: bobpatin@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 >> 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/ >> (warning, it does show the alert when you visit the page) >> > > _______________________________________________ > FX.php_List mailing list > FX.php_List@mail.iviking.org > http://www.iviking.org/mailman/listinfo/fx.php_list > -- John A. "Art" Anderson University of Illinois at Chicago From bob at patin.com Thu Dec 4 12:06:47 2014 From: bob at patin.com (Bob Patin) Date: Thu Dec 4 12:01:41 2014 Subject: [FX.php List] [OFF] Javascript question--comparing dates In-Reply-To: References: <6505D799-A52C-4FD1-B8F1-E2587F3640B5@patin.com> Message-ID: <0F853014-B2D8-4F27-9DF7-795D8B1FE8F1@patin.com> Good idea, that ought to do it! Thanks, Bob Patin Longterm Solutions bob@longtermsolutions.com 615-333-6858 FileMaker 9, 10, 11, 12 & 13 Certified Developer http://www.longtermsolutions.com - iChat: bobpatin@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 12:31 PM, Anderson, John A. wrote: > > Bob, > > Try this simple modification to Ted's original function, (add after "var > date1 = new Date();" to zero out the time part of the date object), > > date1.setHours(0,0,0,0); > > original function: > http://jsfiddle.net/qpvugLna/1/ (warning, it does show the alert when you > visit the page) > > modified function: > http://jsfiddle.net/5afeLdww/ (ditto warning) > > Art -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.iviking.org/pipermail/fx.php_list/attachments/20141204/96285ae7/attachment-0001.html