There was a disussion on this topic in one of the Macromedia Forums. The consensus was that dateDiff looks at a 24 hour period, not the difference in the day part of the date object, this makes more sense if you consider the time component of the data objects
You are comparing midnight of one day to midnight of the next, expecting that will always be a one day difference. But what about this comparison? 2005-03-14 23:20:00 to 2005-03-15 02:12:00, would a 1 returned as the diffence in days between those values make sense, the difference is only 2 hours and 52 minutes? Lets look at it the other side of a day. Consider 2005-11-03 12:00:00 and 2005-11-05 9:00:00, a difference of 45 hours. This is less then two days, important if one wanted to know if two full days have passed since noon on November 3rd. But if one where to just look at the day parts, a value of 2 would be returned, 3 hours premeturly in this example. If one keeps this in mind, it is easier to understand the value datediff is returning. Whether one agrees that this is the logical behaviour or not is a different question all together. Ian Skinner Dawson, Michael wrote: >Have you applied all the updaters to ColdFusion? There is a known bug >that was fixed with an updater, but I don't know if it would fix this >problem. > >MAD > >-----Original Message----- >From: Marc Campeau [mailto:[EMAIL PROTECTED] >Sent: Thursday, January 20, 2005 6:05 PM >To: CF-Talk >Subject: Unexpeceted behavior of the dateDiff function. > >Hi to all! > >Sorry if this has already been answered but I couldn't find a related >thread in the archives. > >I have an application which makes use of the datediff function to figure >out length of times in days between to dates. In other words, how many >days are there between January 1st and January 31st. > >I've ran into a problem with this app. I've used the next piece of code >to reproduce it. ><cfset dtStart = createDate( 2005, 01, 01 )> <cfloop index="i" from="0" >to="365" step="1"> > <cfoutput> > #i# dateDiff( 'd', #dtStart#, #dateAdd( 'd', i, dtStart )# ): >#dateDiff( 'd', dtStart, dateAdd( 'd', i, dtStart ) )#<br /></cfoutput> ></cfloop> > >When running this piece of code I would have expected the value of "i" >to always be equal to the result of the dateDiff call... how wrong of >me... > >When I run the code, I get this output: >0 dateDiff( 'd', {ts '2005-01-01 00:00:00'}, {ts '2005-01-01 00:00:00'} >): 0 >1 dateDiff( 'd', {ts '2005-01-01 00:00:00'}, {ts '2005-01-02 00:00:00'} >): 1 >2 dateDiff( 'd', {ts '2005-01-01 00:00:00'}, {ts '2005-01-03 00:00:00'} >): 2 [...] >92 dateDiff( 'd', {ts '2005-01-01 00:00:00'}, {ts '2005-04-03 00:00:00'} >): 92 >93 dateDiff( 'd', {ts '2005-01-01 00:00:00'}, {ts '2005-04-04 00:00:00'} >): 92 >94 dateDiff( 'd', {ts '2005-01-01 00:00:00'}, {ts '2005-04-05 00:00:00'} >): 93 [...] >301 dateDiff( 'd', {ts '2005-01-01 00:00:00'}, {ts '2005-10-29 >00:00:00'} ): 300 >302 dateDiff( 'd', {ts '2005-01-01 00:00:00'}, {ts '2005-10-30 >00:00:00'} ): 301 >303 dateDiff( 'd', {ts '2005-01-01 00:00:00'}, {ts '2005-10-31 >00:00:00'} ): 303 [...] >364 dateDiff( 'd', {ts '2005-01-01 00:00:00'}, {ts '2005-12-31 >00:00:00'} ): 364 >365 dateDiff( 'd', {ts '2005-01-01 00:00:00'}, {ts '2006-01-01 >00:00:00'} ): 365 > >As you can see I seem to loose a day on April 4th and gain it back on >October 31st. On my server's timezone setting (Eastern Standard Time - >GMT+5) these date correspond to the Daylight Saving Time date changes. > >I know a day as 24 hours and I can understand why on those days the >difference in hours is 23 and 25 respectively. What I can't undestand is >why the difference in days would be impacted by this. April 4th is not >April 3rd. > >Run this code to see what I mean: ><cfoutput> >DST dates for 2005:<br /> >dateDiff In Hours: dateDiff( 'h', '2005-04-03', '2005-04-04' >):#dateDiff( 'h', '2005-04-03', '2005-04-04' )#<br /> dateDiff In Days: >dateDiff( 'd', '2005-04-03', '2005-04-04' >):#dateDiff( 'd', '2005-04-03', '2005-04-04' )#<br /> > >dateDiff In Hours : dateDiff( 'h', '2005-10-30', '2005-10-31' >):#dateDiff( 'h', '2005-10-30', '2005-10-31' )#<br /> dateDiff In Days : >dateDiff( 'd', '2005-10-30', '2005-10-31' >):#dateDiff( 'd', '2005-10-30', '2005-10-31' )#<br /> </cfoutput> > >Which gives this output: >DST dates for 2005: >dateDiff In Hours: dateDiff( 'h', '2005-04-03', '2005-04-04' ):23 >dateDiff In Hours: dateDiff( 'd', '2005-04-03', '2005-04-04' ):0 >dateDiff In Days : dateDiff( 'h', '2005-10-30', '2005-10-31' ):25 >dateDiff In Days : dateDiff( 'd', '2005-10-30', '2005-10-31' ):1 > >Am I a fool for thinking so? Or is this a bug in the implementation of >the datediff function, probably something to do with rounding? > >-- >Marc > > > > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| Logware: a new and convenient web-based time tracking application. Start tracking and documenting hours spent on a project or with a client with Logware today. Try it for free with a 15 day trial account. http://www.houseoffusion.com/banners/view.cfm?bannerid=67 Message: http://www.houseoffusion.com/lists.cfm/link=i:4:191319 Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4 Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4 Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4 Donations & Support: http://www.houseoffusion.com/tiny.cfm/54

