Date, time and duration functions
These functions return the current date and time (current-date, current-time), move a date by a duration
(add-duration, subtract-duration), and take the parts of a date (year, month, day), of a time (hours,
minutes, seconds) and of a duration (years, months, days).
Related functions and operators have their entries elsewhere:
-
The functions that read a date, a time or a duration from a text are conversion functions: date, time, day-time-duration and year-month-duration.
-
You compute the duration between two dates with the minus operator. You can also add, subtract and multiply durations (see Date and duration arithmetic).
-
In templates, you present dates and times to readers with format-short, format-medium and format-long.
There are two kinds of duration. The length of a duration in years and months, for example P1Y or P6M, depends on
the date to which you apply it. A duration in days, for example P30D, or P2W, which is 14 days, has a fixed
length. The value of a duration field is a duration in days when the unit of the field is days or weeks. It is a
duration in years and months when the unit is years or months (see
Duration).
If an argument of these functions has no value, the result has no value.
current-date
Returns the date on which the expression is evaluated.
current-date() → date
The function takes no argument. The result is the current date, with the time zone of the system that evaluates the
expression. In a rule, this is the date on which the notice is validated. In a template, it is the date on which the
notice is displayed. All calls to current-date in one evaluation return the same date.
Examples
BT-00-StartDate >= current-date()
Checks that a date is not in the past.
BT-00-EndDate <= add-duration(current-date(), P10Y)
Checks that a date is at most ten years ahead.
| New in EFX-2. |
See also: current-time
current-time
Returns the time at which the expression is evaluated.
current-time() → time
The function takes no argument. The result is the current time, with the time zone of the system that evaluates the
expression. All calls to current-time in one evaluation return the same time.
Examples
hours(current-time()) < 12
TRUE in the morning.
| New in EFX-2. |
See also: current-date
add-duration
Adds a duration to a date.
add-duration(<date>, <duration>) → date
- <date>
-
date. The date to start from.
- <duration>
-
duration. The duration to add. A negative duration moves the date back.
A duration in years and months moves the date by that number of months, and keeps the day of the month. When that
day does not exist in the new month, the result is the last day of the month: adding P1M to 31 January 2024 gives
29 February 2024.
A duration in days moves the date by that number of days. A duration that includes hours, minutes or seconds counts as a period of time, and the result keeps only the date: adding 36 hours gives the next day.
The result keeps the time zone of <date>, if it has one.
Restrictions
-
The first argument must be a date and the second a duration.
Examples
add-duration(BT-00-StartDate, P6M) <= BT-00-EndDate
Checks that the end date is at least six months after the start date.
add-duration(BT-00-StartDate, BT-00-Duration)
The end of a period given by its start date and its duration.
add-duration(2024-01-31Z, P1M)
Gives 2024-02-29Z.
Renamed. In EFX-1, this function was called add-measure.
|
subtract-duration
Subtracts a duration from a date.
subtract-duration(<date>, <duration>) → date
- <date>
-
date. The date to start from.
- <duration>
-
duration. The duration to subtract. A negative duration moves the date forward.
subtract-duration moves the date back by the duration, with the same rules as
add-duration: subtracting P1M from
31 March 2024 gives 29 February 2024. A duration that includes hours, minutes or seconds counts as a period of time,
and the result keeps only the date: subtracting 12 hours gives the previous day.
Restrictions
-
The first argument must be a date and the second a duration.
Examples
subtract-duration(BT-00-EndDate, P30D)
The date 30 days before the end date.
BT-00-StartDate >= subtract-duration(current-date(), P1Y)
Checks that a date is at most one year in the past.
Renamed. In EFX-1, this function was called subtract-measure.
|
See also: add-duration, Date and duration arithmetic
year
Returns the year of a date.
year(<date>) → number
- <date>
-
date. The date to read.
The result is the year as written in the date. The time zone of the date does not change it.
Examples
year(BT-00-StartDate)
year(BT-00-EndDate) - year(BT-00-StartDate) <= 4
| New in EFX-2. |
month
Returns the month of a date, as a number from 1 to 12.
month(<date>) → number
- <date>
-
date. The date to read.
The result is the month as written in the date: 1 for January, 12 for December. The time zone of the date does not
change it.
Examples
month(BT-00-StartDate)
month(current-date()) == 12
| New in EFX-2. |
day
Returns the day of the month of a date, as a number from 1 to 31.
day(<date>) → number
- <date>
-
date. The date to read.
The result is the day as written in the date. The time zone of the date does not change it.
Examples
day(BT-00-EndDate)
day(add-duration(BT-00-StartDate, P1D)) == 1
TRUE when the start date is the last day of a month.
| New in EFX-2. |
minutes
Returns the minutes of a time, as a number from 0 to 59.
minutes(<time>) → number
- <time>
-
time. The time to read.
The result is the minutes as written in the time. The time zone of the time does not change it.
Examples
minutes(BT-00-StartTime) == 0
TRUE for a time on the hour.
hours(BT-00-StartTime) * 60 + minutes(BT-00-StartTime)
The number of minutes since midnight.
| New in EFX-2. |
seconds
Returns the seconds of a time.
seconds(<time>) → number
- <time>
-
time. The time to read.
The result is the seconds as written in the time, from 0 to less than 60. It can have a decimal part: the seconds of
09:30:15.5 are 15.5.
Examples
seconds(BT-00-StartTime) == 0
| New in EFX-2. |
years
Returns the number of whole years in a duration.
years(<duration>) → number
- <duration>
-
duration. The duration to read.
For a duration in years and months, the result is the number of whole years: P2Y gives 2 and P18M gives 1.
For a duration in days, the result is 0, however long the duration is. A negative duration gives a negative number.
Examples
years(P18M)
Gives 1.
years(BT-00-Duration) <= 4
Checks a duration field whose unit is years or months.
| New in EFX-2. |
months
Returns the total number of months in a duration.
months(<duration>) → number
- <duration>
-
duration. The duration to read.
For a duration in years and months, the result is the total number of months, years included: P2Y gives 24 and
P1Y6M gives 18. For a duration in days, the result is 0. A negative duration gives a negative number.
Examples
months(P2Y)
Gives 24.
months(BT-00-Duration) <= 48
| New in EFX-2. |
days
Returns the number of whole days in a duration.
days(<duration>) → number
- <duration>
-
duration. The duration to read.
For a duration in days, the result is the number of whole days: P3W gives 21, and a duration of 36 hours gives
1. For a duration in years and months, the result is 0. A negative duration gives a negative number.
Examples
days(P3W)
Gives 21.
days(BT-00-EndDate - BT-00-StartDate) <= 90
Checks that two dates are at most 90 days apart. The difference between two dates is a duration in days.
| New in EFX-2. |
See also: years, months, day, Date and duration arithmetic