Calculating EndDate from StartDate and number of w

# Thread: Calculating EndDate from StartDate and number of w

1. PersonalFoul Guest

## Calculating EndDate from StartDate and number of w

I&#039;m looking for a formula or site that could assist in showing me how to calculate the enddate based on a startdate and number of weeks.<BR><BR>For example:<BR><BR>StartDate: 5/4/2004<BR>Weeks Available: 4<BR>EndDate: (Would return 6/1/2004 - exactly 4 weeks from the startdate)<BR><BR><BR>It might be possible to convert the date to a raw number like days from the beginning of the year and then add numberOfWeeks * 7 (days per week) and then recalculate the date.<BR><BR>Just not sure what the best way to achieve this would be.

2. Senior Member
Join Date
Dec 1969
Posts
96,118

## Only easy way...

...is to convert the StartDate to milliseconds using the getTime() function, add 4 weeks worth of milliseconds (4 * 7 * 24 * 3600 * 1000), and then convert those milliseconds back to a Date() value.<BR><BR>SO:<BR><BR>&#060;SCRIPT&#062;<BR>var StartDate = new Date( 2004, 4, 4 ); // months start at zero in JS! 4 is May<BR>var millis = StartDate.getTime( );<BR>millis += ( 4 * 7 * 24 * 3600 * 1000 );<BR>var EndDate = new Date( millis );<BR>alert(EndDate);<BR>&#060;/SCRIPT&#062;<BR><BR>Works like a charm.<BR>

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•