Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.datemas.de!weretis.net!feeder1.news.weretis.net!news.solani.org!.POSTED!not-for-mail From: Thomas 'PointedEars' Lahn Newsgroups: comp.lang.javascript Subject: Re: Date arithmetic Date: Fri, 14 Nov 2014 04:34:19 +0100 Organization: PointedEars Software (PES) Lines: 52 Message-ID: <2926232.BIQMcFlBfa@PointedEars.de> References: Reply-To: Thomas 'PointedEars' Lahn Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7Bit X-Trace: solani.org 1415936060 21022 eJwFwYEBwDAEBMCVaN5jnBD2H6F3dqhsB42wtS2JpEtr+Z1YvFTkYQ9YV3q6Xnw+SaRHzv4duhFT (14 Nov 2014 03:34:20 GMT) X-Complaints-To: abuse@news.solani.org NNTP-Posting-Date: Fri, 14 Nov 2014 03:34:20 +0000 (UTC) User-Agent: KNode/4.14.2 X-User-ID: eJwFwQkBACAIBLBKIhxIHN7+EdzASlomChUslrhrOmDt7BMRa9603SYesy5n7GmlPc4jnpZg5OJKnyLcD4M3FjE= Cancel-Lock: sha1:7ARkhU1WcwiI/uUfreTLyYh81ic= X-NNTP-Posting-Host: eJwFwQkRwEAIBDBLfLuAnA5w/iU0gVM5GQQDD++tdouJOaZzNOIGBnLZDEmYHLBedaMl3w/9xA/q Xref: csiph.com comp.lang.javascript:26136 Dr.Kral@nyc.rr.com wrote: > Swifty wrote: >> I have a form which contains two date fields (ID's "from" and "to", if >> you like) and they are filled with a date-filler script in the format >> yyyy-mm-dd >> [...] >> If all three fields are non-blank (and we can ignore error checking as >> this code if for my benefit only) then how can I subtract the two dates, >> to get the number of days (where 2014-11-11 to 2014-11-12 would be 1 day) > > All that has been talked about is, to me, way overkill. You are talking > about two dates in the same year so why not go back to 1968 times (when > you last did homework) and do it that way. > > Go to your calendar and get the 'day of year' number for each and > subtract. Good morning. I suggested that in already. > For your situation, have a month index array with the count and add the > day. It is not necessary to have such an array. There is an easy-to-be found formula that you can use, which derives from the fact that January always has 31 days, February's depend on leap years, hence March's first day number on that, from which the count proceeds in a pattern. > Do for both and subtract. If you have year difference, you can > have a year table also. That is, however, less efficient because you have to determine leap years, i. e., the day number of December 31, for each included year. > Yes you can use the built-in date functions but that is like sending a > battleship after a batch of mosquitoes. No, what *you* are suggesting is that, by comparison. > And you won't have to worry about summer time or leap seconds to mess up > your calculations. But about other things that *you* have not considered. Please get a real name and skip the attribution novel; also, learn to quote. -- PointedEars FAQ: | SVN: Twitter: @PointedEars2 | ES Matrix: Please do not Cc: me. / Bitte keine Kopien per E-Mail.