User Guide Cancel

SetHour

 

Description

Sets the hour on the Date object. This is a member function called by the Date object.

Returns

DateObject

History

New in Adobe ColdFusion (2016 release)

Category

Date and time functions

Syntax

setHour (hour)
setHour (hour)
setHour (hour)

Parameter

Parameter

Description

hour

Required. An integer representing the hour.

Expected values are 0-23, but other values are allowed:

  • -1 results in the last hour of the previous day
  • 24 results in the first hour of the next day

Example

<cfscript>
myDate=now();
WriteOutput(myDate.setHour(18) & "<br/>");
WriteOutput(myDate.setHour(-1) & "<br/>");
WriteOutput(myDate.setHour(24));
</cfscript>
<cfscript> myDate=now(); WriteOutput(myDate.setHour(18) & "<br/>"); WriteOutput(myDate.setHour(-1) & "<br/>"); WriteOutput(myDate.setHour(24)); </cfscript>
<cfscript>
       myDate=now();
       WriteOutput(myDate.setHour(18) & "<br/>");
       WriteOutput(myDate.setHour(-1) & "<br/>");
       WriteOutput(myDate.setHour(24));
</cfscript>

Output

{ts '2018-11-08 18:53:02'}
{ts '2018-11-07 23:53:02'}
{ts '2018-11-08 00:53:02'}

Get help faster and easier

New user?