• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 167
  • Last Modified:

Datecompare compares date AND time - how to compare just date?

I am using datecompare in this manner:


However, I am not getting the results I'm looking for because the date AND time of now() of being compared to just a date and zero hours.  I just want to compare date for date.  How can I fix this?
David Williamson
David Williamson
2 Solutions
try this...

<CFSET datetimestart = "8/08/04 8:15pm">
<CFSET datetimeend = "8/10/04 1:30am">

#datediff('d',datetimestart,datetimeend)# days
#evaluate(datediff('h',datetimestart,datetimeend) MOD 24)# hours
#evaluate(datediff('n',datetimestart,datetimeend) MOD 60)# minutes
Try this #DateCompare(DateFormat(now(), 'MM/DD/YYYY'), getDD.DueDate)#
If you just want the effects of datecompare with date only then use tim_cs's solution.

If you want to be able to fine-control the comparison use datediff.

Here is a page that explains the first parameter to datediff for the different comparisons

Learn to develop an Android App

Want to increase your earning potential in 2018? Pad your resume with app building experience. Learn how with this hands-on course.

David WilliamsonIT DirectorAuthor Commented:
This seems to do exactly what I'm looking for:

#DateCompare(CreateDate(year(now()),month(now()),day(now())), getFU.FUDueDate)#
Renante EnteraSenior PHP DeveloperCommented:
Hello theamzngq!

You can also do it in this manner :

<cfset Date1 = DateFormat(now(),'yyyy/mm/dd')>
<cfset Date2 = DateFormat(getDD.DueDate,'yyyy/mm/dd')>


eNTRANCE2002 :-)

David WilliamsonIT DirectorAuthor Commented:
I tried this

#DateCompare(DateFormat(now(), 'MM/DD/YYYY'), getDD.DueDate)#

which is essentially what you have written, only broken up into variables, and it didn't work, which is why I went with the above.
What results did my example give you?  I tested it and it worked fine for me.
David WilliamsonIT DirectorAuthor Commented:
sorry for the delay, folks.  haven't been at work for a bit...

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now