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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Changing Dates

Status
Not open for further replies.

LewisReeder

IS-IT--Management
Jul 18, 2005
38
0
0
US
For my application I would like to add validation so that when a user enters a start date, the end date will automatically calculate and generate in the "Week End" field. The week end date will always be 7 days later. The problem arises when the user enters a starting date that is at the end of the month (i.e. 08/27/2005). Since there is no such date as 08/34/2005, how could I have the dates wrap to the next month(09/03/2005)? Someone once told me there was something similar to a "serial number" for every date. Is this true? I have tried to cut the string apart and add the days but the validation will be very tedious and inefficient. Any help would be greatly appreciated.

Thanks,
Lewis
 
Use javascript date objects and the accompanying methods:
Code:
<script language="javascript">
function addWeek(str) {
   var dte = new Date(str);
   dte.setDate(dte.getDate() + 7);
   document.forms['blah'].elements['end'].value = (dte.getMonth() + 1) + "/" + dte.getDate() + "/" + dte.getFullYear();
}
</script>
<body>
<form name="blah">
<input type="text" name="txt" value="08/27/2005">Starting Week<br>
<input type="text" name="end">Ending Week<br>
<input type="button" value="add week" onclick="addWeek(document.forms['blah'].elements['txt'].value)">
</form>
</body>

-kaht

...looks like you don't have a job, so why don't you get out there and feed Tina.
headbang.gif
[rockband]
headbang.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top