Copy link to clipboard
Copied
Hello, everyone,
I'm looping through all the days of the current month, using DateDiff to display the difference in days between the current date and the date of the loop, and I'm getting TWO days showing a difference of 0.
<cfloop from="1" to="#DaysInMonth('01-Nov-14')#" index="ndx">
#DateDiff('d',DateFormat(ndx & '-Nov-14'),now())#<br />
</cfloop>
The output will be
6
5
4
3
2
1
0 <!--- (today, Nov 7) --->
0 <!--- (tomorrow, Nov 8) --->
-1
-2
-3
-4
How can there be two days with a difference of 0?
V/r,
^_^
DateDiff determines the number of complete "datepart" units between the two dates. In your code you are comparing two dates formatted a different way. now() will include the time as well, which when compare to the the other date you formatted (which would have a time of midnight) has a difference between the dates of 7.5 hours (by my time). As you specified 'd' and this difference is not a full 24 hours the difference is 0.
If you do this:
...#DateDiff('d',DateFormat(ndx & '-Nov-14'), DateFormat(now
Copy link to clipboard
Copied
DateDiff determines the number of complete "datepart" units between the two dates. In your code you are comparing two dates formatted a different way. now() will include the time as well, which when compare to the the other date you formatted (which would have a time of midnight) has a difference between the dates of 7.5 hours (by my time). As you specified 'd' and this difference is not a full 24 hours the difference is 0.
If you do this:
#DateDiff('d',DateFormat(ndx & '-Nov-14'), DateFormat(now()) )#
You would get the result you are expecting. You will be comparing like for like date formats.
Copy link to clipboard
Copied
You can't see it, right now, but I'm facepalming myself.
I should have taken that into consideration. I'm one of the few in this dept that will trim(UPPER(query.column)) and trim(ucase(cfValue)) to make absolutely sure a match is correct, and I completely flaked on the time being appended to the date.
Thanks, haxtbh!
^_^