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>
blog comments powered by Disqus

Search CFLib.org


Latest Additions

Kevin Cotton added
date2ExcelDate
May 5, 2016

Raymond Camden added
CapFirst
April 25, 2016

Chris Wigginton added
loremIpsum
January 18, 2016

Gary Stanton added
calculateArrival...
November 19, 2015

Sebastiaan Naafs - van Dijk added
getDaysInQuarter
November 13, 2015

Created by Raymond Camden / Design by Justin Johnson