...

View Full Version : setDate(???) expected parameters



firepages
04-08-2003, 06:00 PM
Hi trying to setDate() but have not a clue of the expected parameters ...

I saw somewhere (where yyyy,dd,mm are integers)

d = new Date();
d.setDate(yyyy,mm,dd);
alert(d.toDateString());

but that always gives an incorrect answer , other variations give NaN .. anyone know what the correct format is ? - or a decent date object reference (I only have MS Jscript reference which is useless)

Spookster
04-08-2003, 06:15 PM
It takes an integer value from 1-31

http://devedge.netscape.com/library/manuals/2000/javascript/1.5/reference/date.html#1194228

firepages
04-08-2003, 07:56 PM
doh , cheers Spookster , why I am looking at MS jscript docs I dont know~

errr still up the spout though , I am trying to add 10 days to a given date from form input...

d= new Date(parseInt(year), parseInt(month), parseInt(day));
var md=d.valueOf() + 86400000 *10;//milliseconds ..should be 10 days ?//
var newdate=new Date(md);
alert(newdate);


it does incrememnt the date by 10 days (mostly)... but also adds one to the month and does weird things at the end of the month ? anyone got a better way for me ?

boywonder
04-08-2003, 08:08 PM
to add 10 days to d

d.setDate(d.getDate() + 10);

firepages
04-09-2003, 03:09 AM
cheers - that works a treat ... still have to -1 from the getMonth() value ? but I can live with that (and its probably something I broke elsewhere anyway ?)

beetle
04-09-2003, 06:10 AM
By default the Date object returns a zero-based value.

Hey firepages, being the PHP person you are, you might appreciate my Date class for JS

http://www.peterbailey.net/dhtml/dates.htm



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum