Skip to main content
Participating Frequently
April 15, 2006
Answered

DateDiff w/ incorrect results (huh?)

  • April 15, 2006
  • 4 replies
  • 759 views
Please run the attached code and tell me I"m not crazy.

DateDiff did not calculate the correct number starting with this date >>> (04/03/2006)... once it hit's that date the count does not increment and then the next date continues incrementing... but with all results now off by one.

What is going on... I need to use DateDiff to get the correct number?

Is there another calculation that I can use to get the difference between two dates... giving me the actual count between those dates? Do you see the same crazy behaviour on your end?

Here is what I see on my side:

(87??) -- 88
(86??) -- 87
86 -- 86
85 -- 85


Thanks for the input.
    This topic has been closed for replies.
    Correct answer Newsgroup_User
    > I'm running ColdFusion Server Standard 6,1,0,63958 on Windows Server 2003.

    You shouyld keep your CF minor version up to date (ie: install the CF
    updaters as they come out).

    Esp in this case, as the CFMX6.1 updater fixes a few date-related bugs
    (incl. ones in dateDiff()).

    Try that first.

    --
    Adam

    4 replies

    Participating Frequently
    April 17, 2006
    Thanks for the input all... the right solution was to update my version of CF. Once I did that, then DateDiff calculated correctly.
    Inspiring
    April 17, 2006
    When having problems with date functions, the first thing you should do is
    to call them properly. dateDiff() takes DATES as the second two arguments,
    not "strings that look like dates". I think it's more a (since fixed...
    see my other response) bug in this case, but you should avoid the
    inclination to rely on CF typecasting your date for you, instead giving it
    thed data types it actually expects.

    Many people on these forums have come a cropper with date functions due to
    passing in ambiguous strings rather than date "objects". It's good
    practice to avoid doing this.

    --
    Adam
    April 17, 2006
    This is working on my cfmx7.01 server. on winxp. What version of CF are you using? What platform? There have been known issues with datediff in older versions of CF.
    Participating Frequently
    April 17, 2006
    oops... I haven't posted in awhile...

    I'm running ColdFusion Server Standard 6,1,0,63958 on Windows Server 2003.

    Is there another way to calculate the amount of days between two dates, considering the years as they roll by... without using DateDiff?

    Thanks
    Participant
    April 15, 2006
    When I run the code, it works fine as expected:

    I did notice in your message you used (87??) and (86??) but in the code you reference (88??) and (87??); with this in mind it sounds like the file didn't update accordingly. I have seen this happen from time to time. Not sure why but it happens.....

    Participating Frequently
    April 15, 2006
    Thanks for the response... I setup a page on my server... check it out.

    http://www.shimogori.com/test1.cfm

    The numbers in the (parens) were added to show what numbers were not calculated correctly by DateDiff.

    Is there another way to calculate amount of days between two dates... keeping in mind the year change?

    Thanks