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

Jon in Chicago, July 2008

I'm Jon Hartmann and I'm a C# .Net developer by day, a ColdFusion guru by night, and all around Javascript fanatic. Stay right here to read my technical posts as I grapple with mysterious error messages, user interface design questions, and all things baffling and irksome about programming for the web. Learn more about me.

Post a job. Find one. authenticjobs.com

Interested in becoming a sponsor? Contact me.