• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Calculating date 5 business days from now

New Here ,
Sep 26, 2006 Sep 26, 2006

Copy link to clipboard

Copied

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...
TOPICS
Advanced techniques

Views

858

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 26, 2006 Sep 26, 2006

Copy link to clipboard

Copied

BusinessDays = "2,3,4,5,6";
NextBusinessDay = dateadd("d", 4, yourdate);
while (ListFind(BusinessDays, day(NextBusinessDay)) is 0) {
NextBusinessDay = dateadd("d", 1, NextBusinessDay);
}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Sep 26, 2006 Sep 26, 2006

Copy link to clipboard

Copied


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!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Sep 26, 2006 Sep 26, 2006

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Sep 26, 2006 Sep 26, 2006

Copy link to clipboard

Copied

BTW, Anyone else getting weird Week() results from the following code?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Sep 26, 2006 Sep 26, 2006

Copy link to clipboard

Copied


> 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!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Sep 26, 2006 Sep 26, 2006

Copy link to clipboard

Copied

{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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Sep 27, 2006 Sep 27, 2006

Copy link to clipboard

Copied

> <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!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Sep 28, 2006 Sep 28, 2006

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Sep 28, 2006 Sep 28, 2006

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Sep 28, 2006 Sep 28, 2006

Copy link to clipboard

Copied

LATEST
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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation