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:191308 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