10 Replies Latest reply on Sep 28, 2006 2:05 AM by Stefan_K.

# Calculating date 5 business days from now

I need to calculate what the date will be 5 business days from a given date. For example, if the date is 9/26/06, a Tuesday, I need to use ColdFusion to return 10/2/06, the following Monday. If the date was 9/25/06, a Monday, I need it to return 9/29, the Friday of that week.

Any ideas are GREATLY appreciated. I don't have much hair left to pull out...
}
• ###### 2. Re: Calculating date 5 business days from now

Another thing to be aware of is what you consider to be a business day.

For example 09-OCT-2006 is a business day for some and not others.
Some banks are closed but the NYSE is open.

Perhaps you can store your business days in a table and query that table?

Good luck!
• ###### 3. Re: Calculating date 5 business days from now
Not to mention that Euro-Weeks start on Monday and Euros (the rest of the world outside US) have a different definition of calendar weeks ... it's called ISO-standards ;-)

Just submitted ISOWeek() udf to cflib.org, post here if you need it and can't wait for their approval.
• ###### 4. Re: Calculating date 5 business days from now
BTW, Anyone else getting weird Week() results from the following code?
• ###### 5. Re: Calculating date 5 business days from now

> Anyone else getting weird Week() results

Not sure what you mean by weird.

Here's what the doc says...

An integer in the range 1–53; the ordinal of the week, within the year.

Good luck!
• ###### 6. Re: Calculating date 5 business days from now
{d '2005-12-25'} 51
{d '2005-12-26'} 53
{d '2005-12-27'} 53
{d '2005-12-28'} 53
{d '2005-12-29'} 53
{d '2005-12-30'} 53
{d '2005-12-31'} 53
{d '2006-01-01'} 52
{d '2006-01-02'} 1
{d '2006-01-03'} 1
• ###### 7. Re: Calculating date 5 business days from now
> <cfset dStart = "{d '2005-12-25'}">
> <cfset dStart = CreateODBCDate(dStart)>
>
> <cfset SetLocale("English (US)")>
>
> <cfloop index="iDate" from="#dStart#" to="#Val(dStart + 14)#">
> <cfoutput>#CreateODBCDate(iDate)# #Week(iDate)#<br></cfoutput>
> </cfloop>

Here are my results...

{d '2005-12-25'} 53
{d '2005-12-26'} 53
{d '2005-12-27'} 53
{d '2005-12-28'} 53
{d '2005-12-29'} 53
{d '2005-12-30'} 53
{d '2005-12-31'} 53
{d '2006-01-01'} 1
{d '2006-01-02'} 1
{d '2006-01-03'} 1
{d '2006-01-04'} 1
{d '2006-01-05'} 1
{d '2006-01-06'} 1
{d '2006-01-07'} 1
{d '2006-01-08'} 2

Win2k/IIS5/CFMX7.02

Your results are weird indeed.

Could it be the loop? I imagine if you were using DateAdd instead
that it would work out correctly?

Good luck!
• ###### 8. Re: Calculating date 5 business days from now
No, my usage of integers as dates is not the problem (tested) and besides that perfectly legal in CF. I don't really have any issues with it since the CF-Week() function is pretty useless outside the US anyways, I'm just wondering.
• ###### 9. Re: Calculating date 5 business days from now
Tested on several servers, CF 4.5, 5.0, 6.x show no problem.
Both tested CF 7.1 Installations show the problem ... interesting.

BTW, what's the best way to report bugs? Over the years I've encountered a few and so far just lived with them.
• ###### 10. Re: Calculating date 5 business days from now
Tested on several servers, CF 4.5, 5.0, 6.x show no problem.
Both tested CF 7.1 Installations show the problem ... interesting.

BTW, what's the best way to report bugs? Over the years I've encountered a few and so far just lived with them.