Click to See Complete Forum and Search --> : Add days to date


teija
09-11-2003, 03:40 AM
How do I add days to date? Example I have in one field a date 11.9.2003 (European date format) and I would like to add 5 days to that date and show it in another form field?

Is there anyway to distinguish saturdays and sundays so that when adding days to date it would add only workdays to the date?

Hope someone can help me on this one!

therealphil
09-11-2003, 06:38 AM
Here's what you need to add days:

var expire = new Date ();
expire.setDay (expire.getDay() + (3)); // adds 3 days

teija
09-12-2003, 12:34 AM
Hi PHP

I wrote the code like this:

var expire = new Date();
expire = txtDate.value;
expire.setDay (expire.getDay() + (10));
txtNewDate.value = expire;

I wanted to get form field :txtDate to variable expire and then add the days (10) - after I tried to put expires value to txtNewDate form field - but It woun't work?

What do I do wrong?

teija

therealphil
09-12-2003, 03:31 AM
This line:

expire = txtDate.value;

is simply copying the value of your 'txtDate' field to the value of your expire variable.

Look:

// this line sets 'expire' to 'new Date()'
var expire = new Date();

// but this line sets expire to the value of 'txtDate'
expire = txtDate.value;
expire.setDay (expire.getDay() + (10));
txtNewDate.value = expire;


Just remove
expire = txtDate.value;

and it should work. Don't trust me on that though,

teija
09-12-2003, 03:50 AM
Hi

I tried to use the setDay-function but I keep getting errormessages. Could it be because I use European timeformat (today: 12.9.2003)?

Here is what I did:

var expire = new Date();
expire = txtDate.value;
expire.setDay (expire.getDay() + (10));
newDate.value = expire;


this is how my txtDate form field is:

<input type=text name='txtDate' size="12" onchange="this.value = new Date(this.value).toDateString()"> <input type=button onClick="window_open()" value='...'>

I'm i hopelesslly stupid or what?

therealphil
09-12-2003, 04:05 AM
I think you need to do this:

function txtDate(){
var txtDate = txtDate.value;
var myDate = txtDate.setDay (txtDate.getDay() + (10));
expire = myDate;
}

and...

<input type="text" name="txtDate" size="12" onchange="txtDate()"> <input type="button" onClick="window_open()" value='...'>