Click here to Skip to main content
15,915,000 members
Home / Discussions / Web Development
   

Web Development

 
GeneralRe: ClientSide JavaScript HTML Tag Pin
alex.barylski23-Jul-04 18:50
alex.barylski23-Jul-04 18:50 
GeneralRe: ClientSide JavaScript HTML Tag Pin
mysorian16-Aug-04 16:43
professionalmysorian16-Aug-04 16:43 
GeneralCalculating Variance excluding non-working days Pin
Ph@ntom20-Jul-04 17:03
Ph@ntom20-Jul-04 17:03 
GeneralRe: Calculating Variance excluding non-working days Pin
Alexander Wiseman2-Aug-04 7:14
Alexander Wiseman2-Aug-04 7:14 
GeneralProblem in playing MPEG-2 video in browser Pin
ckhjacky20-Jul-04 7:50
ckhjacky20-Jul-04 7:50 
Generalshould JMF be installed in all client PC Pin
karthik prasanna20-Jul-04 3:08
karthik prasanna20-Jul-04 3:08 
GeneralAdding number of days to a Date Pin
Ph@ntom19-Jul-04 20:34
Ph@ntom19-Jul-04 20:34 
GeneralRe: Adding number of days to a Date Pin
Alexander Wiseman20-Jul-04 4:29
Alexander Wiseman20-Jul-04 4:29 
Hi,

I think this algorithm should work for what you are trying to do (it assumes that Thursday and Friday are the "non-work days":
<br />
function DateAdd(startDate, numDays, numMonths, numYears)<br />
{<br />
var returnDate = new Date(startDate.getTime()) ;<br />
var yearsToAdd = numYears ; <br />
var month = returnDate.getMonth() + numMonths + 1 ;<br />
<br />
if ( month > 11 )<br />
{<br />
yearsToAdd = Math.floor((month+1)/12) ;<br />
month -= 12*yearsToAdd ;<br />
yearsToAdd += numYears ;<br />
}<br />
<br />
returnDate.setMonth(month) ;<br />
returnDate.setFullYear(returnDate.getFullYear() + yearsToAdd) ;<br />
<br />
// Before we add the days, make sure to exclude non-work days:<br />
var finalDays = 0;<br />
if(numDays >= 5)<br />
{<br />
    //Since you have 2 non-work days, you basically have a 5-day week:<br />
    var weeks = (numDays / 5);<br />
    finalDays = (weeks * 7);<br />
    numDays -= (weeks * 5);<br />
}<br />
<br />
// numDays is now less than 5:<br />
if(numDays > 0)<br />
{<br />
    var dayOfWeek = returnDate.getDay();<br />
   <br />
    // See if, adding the days, we land on or pass any non-work days:<br />
    if(dayOfWeek < 4 && (dayOfWeek + numDays) >= 4)<br />
    {<br />
        finalDays += (numDays + 2); //effectively skips Thursday and Friday<br />
    }<br />
    else<br />
    {<br />
	if(dayOfWeek == 4 || dayOfWeek == 5)<br />
        {<br />
            finalDays += (numDays + (5-dayOfWeek));<br />
        }<br />
        else<br />
            finalDays += numDays;<br />
    }<br />
}<br />
<br />
// Now finalDays contains the number of days we want to add:<br />
returnDate.setTime(returnDate.getTime()+60000*60*24*finalDays);<br />
<br />
return returnDate;<br />
}<br />

I didn't test the code, but I think it should work. Let me know if it doesn't, or if you have more questions.

[EDIT]
Sorry, slight mistake in the function if dayOfWeek = 6. Now it is fixed
[/EDIT]

Sincerely,
Alexander Wiseman

Est melior esse quam videri
It is better to be than to seem
GeneralRe: Adding number of days to a Date Pin
Ph@ntom20-Jul-04 16:59
Ph@ntom20-Jul-04 16:59 
GeneralRe: Adding number of days to a Date Pin
Ph@ntom20-Jul-04 19:13
Ph@ntom20-Jul-04 19:13 
GeneralRe: Adding number of days to a Date Pin
Alexander Wiseman21-Jul-04 3:31
Alexander Wiseman21-Jul-04 3:31 
GeneralRe: Adding number of days to a Date Pin
Ph@ntom23-Jul-04 17:48
Ph@ntom23-Jul-04 17:48 
GeneralRe: Adding number of days to a Date Pin
Alexander Wiseman25-Jul-04 3:22
Alexander Wiseman25-Jul-04 3:22 
GeneralRe: Adding number of days to a Date Pin
Ph@ntom25-Jul-04 6:16
Ph@ntom25-Jul-04 6:16 
GeneralRe: Adding number of days to a Date Pin
Ph@ntom26-Jul-04 6:12
Ph@ntom26-Jul-04 6:12 
GeneralRe: Adding number of days to a Date Pin
Alexander Wiseman27-Jul-04 8:00
Alexander Wiseman27-Jul-04 8:00 
GeneralRe: Adding number of days to a Date Pin
Ph@ntom27-Jul-04 19:40
Ph@ntom27-Jul-04 19:40 
GeneralRe: Adding number of days to a Date Pin
Alexander Wiseman28-Jul-04 4:31
Alexander Wiseman28-Jul-04 4:31 
GeneralRe: Adding number of days to a Date Pin
Ph@ntom30-Jul-04 18:57
Ph@ntom30-Jul-04 18:57 
GeneralRe: Adding number of days to a Date Pin
Alexander Wiseman2-Aug-04 7:15
Alexander Wiseman2-Aug-04 7:15 
GeneralCalling Web Services from a web page Pin
NiteShade19-Jul-04 6:36
NiteShade19-Jul-04 6:36 
GeneralRe: Calling Web Services from a web page Pin
VenkatFor.NET21-Jul-04 8:08
VenkatFor.NET21-Jul-04 8:08 
GeneralRe: Calling Web Services from a web page Pin
mysorian11-Aug-04 11:41
professionalmysorian11-Aug-04 11:41 
GeneralLocalHost and Browser Pin
ohdil16-Jul-04 8:41
ohdil16-Jul-04 8:41 
GeneralRe: LocalHost and Browser Pin
Javier Lozano18-Jul-04 17:01
Javier Lozano18-Jul-04 17:01 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.