|
Mailing Lists
|
Home /
Groups /
ColdFusion Talk (CF-Talk)
Is this a DateDiff() bug?
ColdFusion 5:Jim McAtee 06/04/04 08:54 P there are problems with dateDiff(), for certain. try dates that spanTony Weeg 06/04/04 09:40 P Not a bug, look in the help:Pascal Peters 06/05/04 04:17 A OK. I see that now in the documentation. Doesn't make much sense to me,Jim McAtee 06/05/04 03:00 P Yeah, I wrote it to help someone out with a specific problem. Glad itPascal Peters 06/05/04 06:09 P This is what I ended up with:Jim McAtee 06/06/04 06:29 P ColdFusion 5: <cfoutput> <pre> DateDiff("d", "5/1/2004", "5/31/2004") = #DateDiff("d", "5/1/2004", "5/31/2004")# DateDiff("w", "5/1/2004", "5/31/2004") = #DateDiff("w", "5/1/2004", "5/31/2004")# DateDiff("ww", "5/1/2004", "5/31/2004") = #DateDiff("ww", "5/1/2004", "5/31/2004")# </pre> </cfoutput> Gives: DateDiff("d", "5/1/2004", "5/31/2004") = 30 DateDiff("w", "5/1/2004", "5/31/2004") = 4 DateDiff("ww", "5/1/2004", "5/31/2004") = 4 The docs state that "w" should return the number of "Weekdays", which I take to mean the number days between the two dates, minus days that fall on a weekend. By poking different dates into the two fields I can get the w and ww results to differ by one, but most often they're the same. Bug? there are problems with dateDiff(), for certain. try dates that span Daylight Savings time, I thought the bug was fixed, but I kinda think that one of the patches, made it wrong again, I cant say for certain, but, most likely. ....tony Tony Weeg sr. web applications architect navtrak, inc. tony@navtrak.net 410.548.2337 www.navtrak.net Visit http://www.antiwrap.com the next time you want to send a link to a friend. ColdFusion 5: <cfoutput> <pre> DateDiff("d", "5/1/2004", "5/31/2004") = #DateDiff("d", "5/1/2004", "5/31/2004")# DateDiff("w", "5/1/2004", "5/31/2004") = #DateDiff("w", "5/1/2004", "5/31/2004")# DateDiff("ww", "5/1/2004", "5/31/2004") = #DateDiff("ww", "5/1/2004", "5/31/2004")# </pre> </cfoutput> Gives: DateDiff("d", "5/1/2004", "5/31/2004") = 30 DateDiff("w", "5/1/2004", "5/31/2004") = 4 DateDiff("ww", "5/1/2004", "5/31/2004") = 4 The docs state that "w" should return the number of "Weekdays", which I take to mean the number days between the two dates, minus days that fall on a weekend. By poking different dates into the two fields I can get the w and ww results to differ by one, but most often they're the same. Bug? Not a bug, look in the help: "w" number of weeks between the two dates "ww" number of calendar weeks (Sundays) between the two dates The result between the two would differ if you have less than 7 days with a Sunday that doesn't fall on the first date. I think posted a function to return the number of weekdays (as you define it) on this list a few days ago: function WeekdaysBetween(date1,date2){ var out = 0; var tmp = ""; if(DateCompare(date1,date2) GT 0){ tmp = date1; date1 = date2; date2 = tmp; } if(DayOfWeek(date1) IS 1) date1 = DateAdd("d",-2,date1); if(DayOfWeek(date1) IS 7) date1 = DateAdd("d",-1,date1); if(DayOfWeek(date2) IS 1) date2 = DateAdd("d",+1,date2); if(DayOfWeek(date2) IS 7) date2 = DateAdd("d",+2,date2); out = DateDiff("d",date1,date2); if(DayOfWeek(date2) LT DayOfWeek(date1)) out = out - 2; out = out - (out\7)*2; return out; } Pascal ----- Excess quoted text cut - see Original Post for more ----- OK. I see that now in the documentation. Doesn't make much sense to me, but I'm guessing there's some use for that behavior. I've looked at your function and it's close to what I'm looking for, but I need to modify it to make it inclusive of the end dates. ----- Excess quoted text cut - see Original Post for more ----- Yeah, I wrote it to help someone out with a specific problem. Glad it can give you something to start with. Pascal ----- Excess quoted text cut - see Original Post for more ----- This is what I ended up with: // // Return the number of weekdays in a date range, inclusive // of the beginning and end dates. // function Workdays(date1, date2) { var adjust = 0; var s = IIf(DateCompare(date1, date2) gt 0, 'date2', 'date1'); var e = IIf(DateCompare(date1, date2) gt 0, 'date1', 'date2'); var ws = DayOfWeek(s); var we = DayOfWeek(e); if (ws eq 1 or ws eq 7) adjust = (7 - ws + we - 1) mod 6; else if (we eq 6 or we eq 7) adjust = 7 - ws; else adjust = ((5 - ws + we) mod 5) + 1; return ((e - s) \ 7) * 5 + adjust; } ----- Excess quoted text cut - see Original Post for more -----
|
September 06, 2010
|
Latest Fusion Authority Articles
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||