Dates should be sortable and human-readable at the same time. Unix timestamps are sortable but unreadable. Most date strings are readable but not sortable. YYYYMMDDHHMMSSms is both - common among developers, yet never formally standardized.
Useful for console logging, generating IDs, naming files, and more.
Module Installation
npm i datrpnpm add datrbun i datrdeno add npm:datrModule Usage
import datr from 'datr';
typeof datr();
// string
datr();
// 20260508
datr({ precision: 'seconds' });
// 20260508104700
datr({ precision: 'ms', separator: '-' });
// 20260508-104700-001
datr({ date: '2026-05-08', precision: 'seconds' });
// 20260508000000The datr function accepts an optional options object:
| Option | Type | Default | Description |
|---|---|---|---|
precision |
'day' | 'seconds' | 'ms' |
'day' |
Smallest unit in the output. |
separator |
string |
'' |
String inserted between blocks. |
date |
Date | string | number |
new Date() |
Date to format (Date object, ISO string, or timestamp). |
CLI installation
npm i -g datrpnpm add -g datrbun i -g datrdeno i -g datrCLI usage
datr
# 20260508
datr --precision seconds
# 20260508104700
datr --precision ms --separator -
# 20260508-104700-001
datr --date 2026-05-08 --precision seconds
# 20260508000000
datr --version
# 4.0.0
datr --help
# Usage: datr [options] ...All options also support short flags: -p, -s, -d, -v, and -h.
datr -d "$(date)" -p ms -s -
# 20260508-104700-222CLI usage without installation
npx datrpnx datrbunx datrdeno run npm:datrThe API has changed from positional arguments to a single options object.
| v3 (Positional) | v4 (Object) |
|---|---|
datr() |
datr() |
datr(1) |
datr({ precision: 'seconds' }) |
datr(2) |
datr({ precision: 'ms' }) |
datr(2, '-') |
datr({ precision: 'ms', separator: '-' }) |