Skip to content

@sqlrooms/utils / formatTimeRelative

Function: formatTimeRelative()

formatTimeRelative(d): string

Formats a date relative to the current time (e.g., "2 hours ago", "in 3 days")

Parameters

ParameterTypeDescription
dundefined | null | string | number | Dayjs | DateDate to format (accepts any dayjs ConfigType)

Returns

string

Human-readable relative time string

Example

ts
formatTimeRelative(new Date(Date.now() - 3600000)); // "1 hour ago"