system.date.*Between

Description

This function is a set of functions that include:

Function

Description

system.date.millisBetween

Calculates the number of whole milliseconds between two dates.

system.date.secondsBetween

Calculates the number of whole seconds between two dates.

system.date.minutesBetween

Calculates the number of whole minutes between two dates.

system.date.hoursBetween

Calculates the number of whole hours between two dates.

system.date.daysBetween

Calculates the number of whole days between two dates. Daylight savings changes are taken into account.

system.date.weeksBetween

Calculates the number of whole weeks between two dates.

system.date.monthsBetween

Calculates the number of whole months between two dates. Daylight savings changes are taken into account.

system.date.yearsBetween

Calculates the number of whole years between two dates. Daylight savings changes are taken into account.

Order does matter for the two dates passed in that we are calculating how much time has passed from date 1 to date 2. So, if date 2 is further in time than date 1, then a positive amount of time has passed. If date 2 is backwards in time from date 1, then a negative amount of time has passed.

Syntax

system.date.*between ( date_1, date_2 )

  • Parameters

Date date_1 - The first date to use.

Date date_2 - The second date to use.

  • Returns

Int - An integer that is representative of the difference between two dates.

  • Scope

All

Code Examples
Code Snippet
#This example would grab the current time, and add 119 minutes to it, then calculate the number
#of hours between the two dates.
first = system.date.now()
second = system.date.addMinutes(first, 119)
print system.date.hoursBetween(first, second)#This would print 1 since it is only 1 whole hour.
Code Snippet
#This example would create two date objects, one on the 28th of May,
#and one on the 22nd of April, both in 2018. Because the second date is
#before the first date, a negative number will be returned.
first = system.date.getDate(2018, 4, 28)
second = system.date.getDate(2018, 3, 22)
print system.date.daysBetween(first, second) #This will print -36
Code Snippet
#This example can be placed on the action performed event of a button.
#It will then grab the week difference of two calendar components,
#and enter the value returned into a numeric text field.
 
first = event.source.parent.getComponent('Start Date Calendar').date
second = event.source.parent.getComponent('End Date Calendar').date
event.source.parent.getComponent('Numeric Text Field').intValue = system.date.weeksBetween(first, second)