Choose where you’d like to start

hoursBetween

Overview

The hoursBetween function takes two date-time values as arguments and returns the number of hours between them.

Return Type

  • Number

Syntax

<variable> = <startDateTimeValue>.hoursBetween(<endDateTimeValue>);

(OR)

<variable> = hoursBetween(<startDateTimeValue>, <endDateTimeValue>);

where:

ParameterData typeDescription
variableNUMBERThe number of hours between the specified start and end date-time values,
startDateTimeValueDATE-TIMEThe starting date-time value.
endDateTimeValueDATE-TIMEThe ending date-time value.
Note:
  • Please refer this help document to learn about the supported date-time formats.
  • This function does not calculate the minutes and seconds difference between the start and end time.
  • If the start date-time is larger than the end date-time, the function returns a negative value.
  • A runtime error will be encountered if:
    • Date value exceeds the number of days in that month.
    • Incorrect month value is specified.
    • Incorrect year value is specified.

Example 1

The following example returns the number of hours between the given time values - '18-Dec-2019 09:00:00' and '19-Dec-2019 10:00:00', i.e., it returns 25.

start_time = '18-Dec-2019 09:00:00'; 
end_time = '19-Dec-2019 10:00:00'; 
total_hours = hoursBetween(start_time, end_time); 
// The value of total_hours is 25

Example 2

The following example returns the number of hours between the given time values - '18-Dec-2019 07:00:00' and '18-Dec-2019 08:59:59', i.e., it returns 1 as the minutes and seconds difference will not be calculated.

start_time = '18-Dec-2019 07:00:00'; 
end_time = '18-Dec-2019 08:59:59'; 
total_hours = hoursBetween(start_time, end_time); 
// The value of total_hours is 1

Get Started Now

Execute