## GetNearestHalfHour(minutes)

##### Last updated March 10, 2003

**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;
}
```

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