In comp.lang.javascript message <
[email protected]
See FAQ 2.3.
it all started with the following function. I am bad at math and dates
and while looking over some date methods I came up with this...
Perhaps you did not see what our FAQ says about it?
// Basic Date Arithmetic
var dateObject = new Date(2007, 9, 27);
// 01: this version can only do addition :/
function bda0(d, h, i) {
var d = new Date(d);
Inefficient (and unreliable for AD<100). Use
var d = new Date(+d);
return new Date(d['set' + h](d['get' + h]() + i));
= return d.setDate(d.getDate()+i) // etc.
Note that, while incrementing seconds and milliseconds is
straightforward (and can be done with getTime & setTime), doing it with
[minutes, ] hours, days, months, years can lead to surprises, since
[hours, ] days, months, years vary in length. Therefore, performing
simple addition without giving appropriate special treatment is unwise.
Consider adding a month to January 29th in Arizona.
It's a good idea to read the newsgroup c.l.j and its FAQ. See below.
--
(c) John Stockton, Surrey, UK.
[email protected] Turnpike v6.05 IE 6
FAQ <URL:
http://www.jibbering.com/faq/index.html>.
<URL:
http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:
http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.