Global Helpers
timeAgoInWords()
Signature
Section titled “Signature”timeAgoInWords() — returns any
Available in: controller, model, mapper, migrator, migration, tabledefinition
Category: Date Functions
Description
Section titled “Description”Returns a string describing the approximate time difference between the date passed in and the current date.
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. Show how long ago a date was (relative to now)
aWhileAgo = DateAdd("d", -90, Now());
// Returns something like "3 months"
writeOutput(timeAgoInWords(aWhileAgo));
// 2. Include seconds for a very recent timestamp
justNow = DateAdd("s", -8, Now());
// Returns "less than 10 seconds"
writeOutput(timeAgoInWords(fromTime=justNow, includeSeconds=true));
// 3. Compare against a specific reference point instead of now
postDate = CreateDateTime(2024, 1, 15, 9, 0, 0);
referenceDate = CreateDateTime(2024, 3, 20, 9, 0, 0);
// Returns "about 2 months"
writeOutput(timeAgoInWords(fromTime=postDate, toTime=referenceDate));