Click here to Skip to main content
15,925,309 members
Home / Discussions / Web Development
   

Web Development

 
GeneralRe: Javascript regex to strip tag Pin
alex.barylski24-Jul-04 9:58
alex.barylski24-Jul-04 9:58 
GeneralRe: Javascript regex to strip tag Pin
Richard Deeming5-Aug-04 8:30
mveRichard Deeming5-Aug-04 8:30 
Generaldetecting when a button is pressed Pin
kyleiscool200423-Jul-04 9:32
kyleiscool200423-Jul-04 9:32 
GeneralRe: detecting when a button is pressed Pin
alex.barylski23-Jul-04 18:51
alex.barylski23-Jul-04 18:51 
GeneralRe: detecting when a button is pressed Pin
Anonymous30-Jul-04 7:39
Anonymous30-Jul-04 7:39 
GeneralFrames Pin
kyleiscool200423-Jul-04 9:26
kyleiscool200423-Jul-04 9:26 
GeneralRe: Frames Pin
alex.barylski23-Jul-04 18:53
alex.barylski23-Jul-04 18:53 
GeneralNavigate from Child to Parent Pin
KKCodePro22-Jul-04 16:06
KKCodePro22-Jul-04 16:06 
GeneralRe: Navigate from Child to Parent Pin
alex.barylski23-Jul-04 18:55
alex.barylski23-Jul-04 18:55 
GeneralOCX / Cab / CODEBASE Pin
RichardGrimmer22-Jul-04 2:40
RichardGrimmer22-Jul-04 2:40 
GeneralRe: OCX / Cab / CODEBASE Pin
OBRon22-Jul-04 5:10
OBRon22-Jul-04 5:10 
GeneralRegular Expressions Pin
jazz081521-Jul-04 5:01
jazz081521-Jul-04 5:01 
GeneralRe: Regular Expressions Pin
Javier Lozano22-Jul-04 14:14
Javier Lozano22-Jul-04 14:14 
GeneralTextArea and <HTML> tag Pin
devvvy20-Jul-04 20:13
devvvy20-Jul-04 20:13 
GeneralRe: TextArea and <HTML> tag Pin
alex.barylski23-Jul-04 18:49
alex.barylski23-Jul-04 18:49 
GeneralClientSide JavaScript HTML Tag Pin
gmhanna20-Jul-04 18:20
gmhanna20-Jul-04 18:20 
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 

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.