Click here to Skip to main content
15,919,500 members
Home / Discussions / Web Development
   

Web Development

 
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 
Hey,

I've worked out the DateVariance function. The function below returns the number of non-working days (non-Thursdays/Fridays) between the two given dates (startDate and endDate).

Here is the function:
function DateVariance(startDate, endDate)
{

var diffMS = (endDate.getTime() - startDate.getTime());

//Get number of days from diffMS:
var days = Math.floor(diffMS / (1000 * 3600 * 24));

//If days == 0, return 0:
if(days == 0)
	return days;

var nonworkdays = 0;

//Resolve into weeks:
var weeks = Math.floor(days / 7);
if(weeks > 0)
{
	days -= weeks;
	nonworkdays += (weeks * 2);
}

//Now days < 7:
if(days > 0)
{
	var dayofweek = startDate.getDay();

	if(dayofweek < 5)
	{

		if(dayofweek == 4) // Thursday
			nonworkdays++;
		else
		{
			if(days > (4 - dayofweek))
				nonworkdays += 2;
		}
	}
	else
	{
		if(dayofweek == 5 /* Friday */ && days == 6)
			nonworkdays++;
		else if(dayofweek == 6 /* Saturday */ && days >= 5)
			nonworkdays += (days == 5 ? 1:2);
	}
}

//Return number of non work days between the two dates:
return (days-nonworkdays);

}

Basically what this does is as follows:

1) Get difference (in milliseconds) between the two different dates
2) Convert those milliseconds into number of whole days between the two dates
3) Convert that number of days into number of whole weeks between the two dates
4) For every week between the two dates, add 2 to a variable called nonworkdays -- this var will keep track of the non-work days between the two dates
5) Now, subtract out (7 * weeks) from days so we're left with a number for days that is less than 7.
6) With that number of days (if it is greater than 0) perform the following to add more work days:

6a) If the day of the week is Thursday, add 1 more work day to the total non-work days
6b) If the day of the week is less than Thursday (i.e. Sunday-Wednesday) add 2 work days if, by adding the remaining number of days to the current day of the week, we pass wednesday (in which case we're passing Thursday and Friday, so we have to add 2 to nonworkdays), otherwise, don't add anything to nonworkdays (because we don't pass Thursday and Friday).
6c) If the day of the week is Friday AND days is 6, then we need to add 1 to nonworkdays (because otherwise we'll land on a Thursday).
6d) If the day of the week is Saturday, add 2 non work days if days==6 (because otherwise we will land on Friday) or 1 non work day if days==5 (because otherwise we will lang on Thursday).

7) Finally, return days - nonworkdays which will be the total non-work days between the two given dates.

[EDIT] I removed the document.write line from the function. Obviously, that was there for testing purposes only! [/EDIT]

Hope that helps!

Sincerely,
Alexander Wiseman
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 
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 

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.