PHP date() to JavaScript date-fns format() Converter

Paste a PHP date() format string to get the equivalent date-fns format() token string used by JavaScript and TypeScript projects.

Token-by-token mapping

Shown one token at a time — some dialects combine two adjacent tokens (like a day number plus an ordinal suffix) into a single result above, which can differ slightly from this per-token view.

Close equivalent Covers the common case, but has documented behavioral differences.

PHP date()
Y-m-d H:i:s
JavaScript (date-fns)
yyyy-MM-dd HH:mm:ss

Main limitation: date-fns tokens are letter-repetition based (`d` vs `dd`, `M` vs `MM` vs `MMM` vs `MMMM`) rather than PHP's one-character-per-meaning scheme, so converting requires counting repeated letters, not just swapping single characters.

How it differs

  • date-fns tokens are letter-repetition based (d vs dd, M vs MM vs MMM vs MMMM) rather than PHP's one-character-per-meaning scheme, so converting requires counting repeated letters, not just swapping single characters.
  • date-fns's ordinal-day token is the two-letter do, which (like MySQL's %D) represents the day number *and* its suffix together — this converter fuses PHP's adjacent j/d + S into a single do automatically.
  • date-fns literal text is wrapped in single quotes when it contains letters (e.g. 'at'), whereas PHP escapes each special character individually with a backslash.

Examples

Standard timestamp

PHP date() Y-m-d H:i:s
JavaScript (date-fns) yyyy-MM-dd HH:mm:ss

Straightforward 1:1 mapping once you know date-fns's letter-repetition rule.

Ordinal day, fused automatically

PHP date() l, jS F Y
JavaScript (date-fns) EEEE, do MMMM yyyy

PHP's adjacent `j` (day, no leading zero) and `S` (ordinal suffix) are fused into date-fns's combined `do` token — the conversion is exact, not lossy.

Edge cases

Edge case

PHP's u (microseconds) has no date-fns equivalent — date-fns's S-family tokens only go down to milliseconds (SSS).

Edge case

If PHP's S (ordinal suffix) appears without an adjacent day token immediately before it, it cannot be fused into do and is dropped with a warning instead of guessed.

References

  • PHP Manual — date() — checked 2026-07-29
  • date-fns — format() — checked 2026-07-29

Last verified 2026-07-29.