CFLib.org – Common Function Library Project

isTimeBetween(minTime, maxTime[, time])

Last updated August 10, 2006

author

Anthony Galano

Version: 1 | Requires: CF6 | Library: DateLib

Description:
Useful for checking if a time is between a time range. For instance, if the current time is between 12 and 1 pm then execute or display some code.

Return Values:
Returns a boolean.

Example:

<!--- create a time at 12:00 pm --->
<cfset minTime = CreateTime(12,00,00)>
<!--- create a time at 1:00 pm --->
<cfset maxTime = CreateTime(13,00,00)>
<!--- check if the current time is between 12 and 1 pm --->
<cfif IsCurrentTimeBetween(minTime,maxTime)>
It is between 12 and 1 pm
<cfelse>
It is NOT between 12 and 1 pm
</cfif>

Parameters:

Name Description Required
minTime The lower range of time. Yes
maxTime The upper range of time. Yes
time The time to check. Defaults to now(). No

Full UDF Source:

<!---
 Returns true/false if a time is between the supplied start/end times.
 v2 by Raymond Camden
 
 @param minTime      The lower range of time. (Required)
 @param maxTime      The upper range of time. (Required)
 @param time      The time to check. Defaults to now(). (Optional)
 @return Returns a boolean. 
 @author Anthony Galano (anthony@webpex.com) 
 @version 1, August 10, 2006 
--->
<cffunction name="isTimeBetween" access="public" returntype="boolean" output="false">
    <cfargument name="minTime" type="date" required="true">
    <cfargument name="maxTime" type="date" required="true">
    <cfargument name="time" type="date" required="false" default="#now()#">
    
    <cfset var curTime = createTime(timeFormat(arguments.time,"H"),timeFormat(arguments.time,"mm"),timeFormat(arguments.time,"ss"))>
    <cfif dateDiff("n",minTime,curTime) gt 0 and
          dateDiff("n",maxTime,curTime) lt 0>
        <cfreturn true>
    <cfelse>
        <cfreturn false>
    </cfif> 
       
</cffunction>

Search CFLib.org


Latest Additions

Raymond Camden added
QueryDeleteRows
November 04, 2017

Leigh added
nullPad
May 11, 2016

Raymond Camden added
stripHTML
May 10, 2016

Kevin Cotton added
date2ExcelDate
May 05, 2016

Raymond Camden added
CapFirst
April 25, 2016

Created by Raymond Camden / Design by Justin Johnson