Closed Thread Icon

Preserved Topic: Add Date function Pages that link to <a href="https://ozoneasylum.com/backlink?for=18546" title="Pages that link to Preserved Topic: Add Date function" rel="nofollow" >Preserved Topic: Add Date function\

 
Author Thread
bianca
Obsessive-Compulsive (I) Inmate

From:
Insane since: Aug 2002

posted posted 09-04-2002 04:11

Do you know of a function in javascript that adds the number of days to the specified date? I'm having problems with the program I'm creating. Thankss...

Slime
Lunatic (VI) Mad Scientist

From: Massachusetts, USA
Insane since: Mar 2000

posted posted 09-04-2002 05:23

How is the date specified?

The best way is to create a Date object, load the date into it, change it with that (Javascript will handle all the annoyances of dates this way), and then get the new date back out of it.

lallous
Paranoid (IV) Inmate

From: Lebanon
Insane since: May 2001

posted posted 09-04-2002 09:22

This code is not mine, but your question was nice and thought I'ld see an answer for myself too:

code:
<script language="JavaScript">
<!--
Time = new Date();

day = 27;
month = 2;
year = 1996;

Time.setDate (day);
Time.setMonth(month-1);
Time.setYear (year);

oldDate = Time.getTime();
daysToAdd = 5;

newDate = oldDate + (daysToAdd*24*60*60*1000);
Time.setTime(newDate);
//-->
</script>



He's using getTime() then converting the days to millseconds.

Hope that helps.

bianca
Obsessive-Compulsive (I) Inmate

From:
Insane since: Aug 2002

posted posted 09-04-2002 11:38

hey... thanks a lot...

« BackwardsOnwards »

Show Forum Drop Down Menu