Utility Function: DateBetween()

I get so tired of doing date comparisons to see if a date is between two other dates. Its not hard, but I always feel like it should be a method.


<cffunction name="DateBetween" output="false" access="public" returntype="boolean">
    <cfargument name="testDate" type="date" required="true" />
    <cfargument name="lowDate" type="date" required="true" />
    <cfargument name="highDate" type="date" required="true" />
    <cfargument name="inclusive" type="boolean" required="false" default="true" />
    
    <cfif arguments.inclusive>
        <cfreturn (lowDate lte testDate AND testDate lte highDate) />
    <cfelse>
        <cfreturn (lowDate lt testDate AND testDate lt highDate) />
    </cfif>
</cffunction>

 

Related Blog Entries

Comments are not allowed for this entry.
Jon Hartmann, July 2011

I'm Jon Hartmann and I'm a Javascript fanatic, UX/UI evangelist and former ColdFusion master. I blog about mysterious error messages, user interface design questions, and all things baffling and irksome about programming for the web.

Learn more about me on LinkedIn.