Would this be more efficient?
<cfscript>
// My test dates
// form.leadtime = 19;
// form.needby = CreateDate(2002,02,05);
// Get the number of weeks in the lead time
weeksinleadtime = form.leadtime/5;
fullweeks = Int(weeksinleadtime);
// work out if there are extra days
extradays = (weeksinleadtime-fullweeks)*5;
// work out the days for the full weeks
weeksleadtime = (fullweeks*7);
// Find out what the date is for the full weeks
// so that I can find out what day of the week it is
StartDate = DateAdd("d",-weeksleadtime,form.needby);
// if the extra days run over a weekend then account for those by adding 2
extra days
if (evaluate(DayofWeek(startdate)-extradays) lt 1)
extradays = extradays+2;
// add it all together
realleadtime = weeksleadtime+extradays;
// Spit out my start date
StartDate = DateAdd("d",-realleadtime,form.needby);
</cfscript>
BTW - nice little puzzle....
Regards
Stephen
----- Original Message -----
From: "Andy Ewings" <[EMAIL PROTECTED]>
To: "CF-Talk" <[EMAIL PROTECTED]>
Sent: Thursday, January 24, 2002 5:09 PM
Subject: RE: Calculating workdays
> I used something like the following to work out the number of working
> days
> between 2 dates. You should be able to manipulate to get what you
> want:
>
> <cfloop condition="#daysadded# LT #stagelength#">
> <cfset nextdate = DateAdd("D",1,nextdate)>
> <cfif DayOfWeek(nextdate) IS NOT 1 AND DayofWeek(nextdate) IS NOT 7>
> <cfset daysadded = daysadded + 1>
> </cfif>
> </cfloop>
>
> -----Original Message-----
> From: Chris Combs [mailto:[EMAIL PROTECTED]]
> Sent: 24 January 2002 17:03
> To: CF-Talk
> Subject: RE: Calculating workdays
>
>
> What DBMS are you working with?
>
> -----Original Message-----
> From: Alex [mailto:[EMAIL PROTECTED]]
> Sent: Thursday, January 24, 2002 11:50 AM
> To: CF-Talk
> Subject: Re: Calculating workdays
>
>
> i have been looking for something like this forever and have not found
> it.
>
> Or even a way to do it without making clunking code.
>
>
> On Thu, 24 Jan 2002, it-werks wrote:
>
> > I could have sworn there was a tag on the developer's exchange, but I
> sur
> e
> > can't find it.
> >
> > I am looking for a tag, formula or whatever is needed to do the
> following
> :
> > When a number is entered into a form field named "leadtime" and a
> date is
> > put in a form field named "need_by" a results field will be the
> calculate
> d
> > date that
> > is the number of WEEKDAYS(mon-fri) BEFORE the Needed Date.
> > In other words: I need the date to order a part which has a leadtime
> of x
> > number of workdays before the needby date.
> >
> > Sure could use some help here.
> >
> > Terry Troxel
> >
> >
>
>
>
______________________________________________________________________
Why Share?
Dedicated Win 2000 Server � PIII 800 / 256 MB RAM / 40 GB HD / 20 GB MO/XFER
Instant Activation � $99/Month � Free Setup
http://www.pennyhost.com/redirect.cfm?adcode=coldfusionc
FAQ: http://www.thenetprofits.co.uk/coldfusion/faq
Archives: http://www.mail-archive.com/[email protected]/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists