Skip to main content Link Search Menu Expand Document (external link)

addHours() : Add Hours to Date


On this page

Summary

Add hours to a datetime. Use negative values to subtract hours.

Signature

addHours(date, hours)

Parameters

Parameter Type Required Description
date DateTime Yes The datetime to modify
hours Number Yes Number of hours to add (can be negative)

Returns

Type: DateTime

A new DateTime with the specified hours added.


Examples

Add Hours

<p>Meeting ends: </p>

Data:

doc.Params["model"] = new {
    startTime = new DateTime(2024, 3, 15, 14, 30, 0)
};

Output:

<p>Meeting ends: 4:30 PM</p>

Delivery Window

<p>Delivery between  and </p>

Data:

doc.Params["model"] = new {
    orderTime = new DateTime(2024, 3, 15, 10, 0, 0)
};

Output:

<p>Delivery between 12:00 PM and 2:00 PM</p>

Time Zone Adjustment

<p>EST: </p>
<p>PST: </p>

Notes

  • Input datetime is not modified (returns new datetime)
  • Can add positive or negative hours
  • Automatically handles day boundaries
  • Use addMinutes() for minute increments
  • Use addDays() for day increments

See Also