Global Helpers
timeAgoInWords()
Signature
Section titled “Signature”timeAgoInWords() — returns any
Available in: controller, model, test, migrator, migration, tabledefinition
Category: Date Functions
Description
Section titled “Description”Returns a human-friendly string describing the approximate time difference between two dates (defaults to comparing against the current time).
Parameters
Section titled “Parameters”| Name | Type | Required | Default | Description |
|---|---|---|---|---|
fromTime | date | yes | — | Date to compare from. |
includeSeconds | boolean | no | false | Whether or not to include the number of seconds in the returned string. |
toTime | date | no | [runtime expression] | Date to compare to. |
Examples
Section titled “Examples”1. Example in a controller (outputs: "3 months")
aWhileAgo = DateAdd("d", -90, Now());
timeAgoInWords(aWhileAgo)
2. Including seconds (outputs: "less than 5 seconds")
timeAgoInWords(DateAdd("s", -3, Now()), includeSeconds=true)
3. Comparing two specific dates (Outputs: "5 months")
past = CreateDateTime(2024, 01, 01, 12, 0, 0);
future = CreateDateTime(2024, 06, 01, 12, 0, 0);
timeAgoInWords(fromTime=past, toTime=future)