Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

adding days to a date 1

Status
Not open for further replies.

craigward

Programmer
Nov 13, 2007
230
GB
Hi,

I have written some code that is nearly doing what i want by adding 365 days to a user defined date but it is treating my date as US format not UK so it's coming up with the wrong result.

Could someone look at it and tell me what i'm doing wrong please? Thanks in advance.

Code:
<html>

<head>
<script language=JavaScript>

function adddate(){

	var cur_priority = "Low";	
	var last_hs = document.forms[0]._last_hs.value;
	var daystoadd = 0;
	
	if (cur_priority == "High"){
		daystoadd = 91;
	}
	else if (cur_priority == "Medium"){
		daystoadd = 182;
	}
	else if (cur_priority == "Low"){
		daystoadd = 365;	
	}
	
		alert(cur_priority);		
		alert(daystoadd);

		
    var d = new Date(last_hs);
	
    d.setDate(d.getDate()+daystoadd);
	
    alert(d.getDate()+"/"+(d.getMonth()+1)+"/"+d.getYear());
	
	document.forms[0]._next_hs.value = d.getDate()+"/"+(d.getMonth()+1)+"/"+d.getYear()

}

</script>

</head>
<body>
<form name=form1>
<table>
<tr><td class=ContactBoldText>Last_HS</td>
<td class=ContactBoldText><input type="text" name=_last_hs value="15/06/2011"></td></tr>
 

<tr><td class=ContactBoldText>next_HS </td>
<td class=ContactBoldText><input type="text" name=_next_hs ></td></tr>

<tr><td><input type=button onclick="adddate()" value=click> </td></tr>

</table>
</form>

</body
</html>
 
Hi

Code:
[gray]// var d = new Date(last_hs); use the following line instead :[/gray]
[b]var[/b] d [teal]=[/teal] [b]new[/b] [COLOR=darkgoldenrod]Date[/color][teal]([/teal]last_hs[teal].[/teal][COLOR=darkgoldenrod]replace[/color][teal]([/teal][fuchsia]/(\d+\/)(\d+\/)/[/fuchsia][teal],[/teal][green][i]'$2$1'[/i][/green][teal]))[/teal]


Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top