Date Utilities
Lightweight date formatting, human relative time, comparisons, and arithmetic in sc-fns/date.
The sc-fns/date module provides zero-dependency date formatting and calculations without the weight of bulky libraries.
ts
formatDate
Formats a Date object or timestamp string using familiar format tokens:
| Token | Description | Example |
|---|---|---|
YYYY | 4-digit year | 2026 |
YY | 2-digit year | 26 |
MM | 2-digit month | 03 |
DD | 2-digit day | 09 |
HH | 2-digit hour (24-hour) | 14 |
hh | 2-digit hour (12-hour) | 02 |
mm | 2-digit minute | 30 |
ss | 2-digit second | 45 |
A | AM / PM | PM |
Signature
ts
Examples
ts
formatRelativeTime
Calculates human-friendly relative time durations (e.g. "just now", "5 minutes ago", "in 2 hours").
Signature
ts
Examples
ts
Date Predicates: isToday, isYesterday, isTomorrow
Tests calendar dates against the reference date (defaults to today).
Examples
ts
addDays & subtractDays
Creates a new Date instance with days added or subtracted without mutating the original Date.
Examples
ts
getDateDifference
Calculates the difference between two dates in days, hours, minutes, seconds, or milliseconds.
Signature
ts
Examples
ts
How is this guide?
Last updated on October 25, 2026