tracker issue : CF-4163932

select a category, or use search below
(searches all categories and all time range)
Title:

DateDiff with a datepart of "w" (Weekdays) gives the number of weeks between two dates instead of Weekdays

| View in Tracker

Status/Resolution/Reason: Closed/Fixed/BugVerified

Reporter/Name(from Bugbase): Dan Murphy / Dan Murphy (Dan Murphy)

Created: 06/13/2016

Components: Language

Versions: 10.0

Failure Type:

Found In Build/Fixed In Build: CF11_Final / 299753,299879,299880,300319

Priority/Frequency: Major / All users will encounter

Locale/System: English / Mac 10 All

Vote Count: 1

Problem Description:
When using the DateDiff function with a datepart of "w" (Weekdays), you get the number of weeks between the two dates instead of Weekdays between the two dates. This is exactly the same as using a date part of "ww" (Weeks). The docs are weird because they say "w: Weekdays (same as ww)". My guess is this was originally a bug and then the docs were just updated to reflect the bug instead of just fixing it or something.

Steps to Reproduce:
<cfscript>
    weeks = dateDiff("w","2016-06-11","2016-06-21");
    WriteDump(weeks);
</cfscript>

Actual Result:
1

Expected Result:
7

Any Workarounds:
Build your own Weekdays function

----------------------------- Additional Watson Details -----------------------------

Watson Bug ID:	4163932

External Customer Info:
External Company:  
External Customer Name: Dan Murphy
External Customer Email:  
External Test Config: My Hardware and Environment details:

Any and all will find the bug

Attachments:

Comments:

Here it is on trycf... http://trycf.com/gist/DVAAE-324588308900feacae6fa48a6fb6f72f/acf2016?theme=monokai
Comment by External U.
2415 | June 13, 2016 09:50:23 PM GMT
+1 - also confirmed same buggy behavior in CF2016: <cfscript> writeDump(dateDiff("w", now(), dateAdd("w", 8, now())));//returns 1 (bad - should return 8) writeDump(dateDiff("ww", now(), dateAdd("ww", 8, now())));//returns 8 (good) </cfscript> So DateDiff has 1) behavior bug and 2) doc bug. The "(same as ww)" should be removed from the "w" description, to match same on DatePart's doc. Thanks!, -Aaron
Comment by External U.
2416 | June 17, 2016 09:19:06 PM GMT
+1 - also confirmed in CF2016
Vote by External U.
2422 | June 17, 2016 09:19:38 PM GMT
So the status has been changed to Fixed (which is great) but can you tell us when or what version it will be fixed in? Thanks!
Comment by External U.
2417 | September 06, 2016 02:15:53 PM GMT
As part of the fix for this bug, the behavior of the datapart character 'w' has been changed to return the number of week days. Documentation will be updated to reflect this behavior. Post this fix, the datapart characters 'w' and 'ww' for the methods dateDiff and dateAdd, will be in sync.
Comment by Immanuel N.
2418 | September 20, 2016 10:00:18 PM GMT
Fix tested on 300359. Testcase already exists in cf/../coretests\coldfusion\functions\date-time\bugs
Comment by Immanuel N.
2419 | October 04, 2016 10:16:16 PM GMT
I still don't see this fixed in the latest CF11 update or CF2016 even though this has been marked as fixed. We've had an update since it was marked as fixed. Am I just not seeing something correctly? Please confirm. Thanks, Dan <cfscript> weekdays = dateDiff("w","2016-06-11","2016-06-21"); weeks = dateDiff("ww","2016-06-11","2016-06-21"); WriteOutput("weekdays (should be 7): " & weekdays); WriteOutput("<br>"); WriteOutput("weeks (should be 1): " & weeks); </cfscript>
Comment by Dan M.
2420 | April 15, 2017 04:42:43 AM GMT
@Dan this is been fixed but we are withholding the fix until the next release for backward compatibility reasons. In case you require the fix urgently please let us know at dabhat@adobe.com Thanks, Dattanand Bhat
Comment by Dattanand M.
2421 | April 17, 2017 05:41:31 AM GMT