CFLib.org – Common Function Library Project

GetNearestHalfHour(minutes)

Last updated March 10, 2003

author

Jason Smith

Version: 1 | Requires: CF5 | Library: DateLib

Description:
We needed a short bit of code to give the nearest half-hour based on 15 minute intervals. This does the trick.

Return Values:
Returns a numeric value.

Example:

<cfset Minutes = Minute(Now())>

<cfoutput>
Current minutes past the hour: #Minutes#<br>
Nearest Half Hour: #GetHalfHour(minutes)#
</cfoutput>

Parameters:

Name Description Required
minutes Number of minutes past the hou for which you want to calculate the nearest half hour. Yes

Full UDF Source:

/**
 * Returns the nearest half hour based on minutes of the hour supplied to the function.
 * 
 * @param minutes      Number of minutes past the hou for which you want to calculate the nearest half hour. (Required)
 * @return Returns a numeric value. 
 * @author Jason Smith (jason@inwebsys.net) 
 * @version 1, March 10, 2003 
 */
function GetHalfHour(minutes) {
  var min_diff = abs(30 - minutes);
  var half_hour = 0;
  if (minutes lte 30) {
    if (min_diff gte 15) { half_hour = "00"; }
    else { half_hour = "30"; }
  } 
  else if (minutes gt 30) {
    if (min_diff gte 15) { half_hour = "00"; }
    else { half_hour = "30"; }
  }
  return half_hour;
}

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