PHP date() to Python strftime() Converter

Paste a PHP date() format string to get the equivalent Python strftime() format — with explicit warnings for anything PHP supports that strftime can't express.

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.

Requires review Works only under specific conditions — read the caveats before relying on it.

PHP date()
Y-m-d H:i:s
Python strftime()
%Y-%m-%d %H:%M:%S

Main limitation: PHP's date() has a dedicated single character for both padded and non-padded day/hour numbers (`d`/`j`, `h`/`g`); Python's strftime has no non-padded day-of-month or 12-hour-hour directive, so `j` and `g` have no exact strftime equivalent.

How it differs

  • PHP's date() has a dedicated single character for both padded and non-padded day/hour numbers (d/j, h/g); Python's strftime has no non-padded day-of-month or 12-hour-hour directive, so j and g have no exact strftime equivalent.
  • PHP's S ordinal suffix (1st, 2nd, 3rd) has no strftime equivalent at all — Python code must compute the suffix manually or use a library.
  • PHP's timezone tokens (e, T, O, P) map onto strftime's %Z/%z, but %Z's exact rendering (abbreviation vs. full name) depends on the platform's C library and the datetime object's tzinfo, not the format string alone.

Examples

Standard timestamp

PHP date() Y-m-d H:i:s
Python strftime() %Y-%m-%d %H:%M:%S

Every token here has a 1:1 strftime equivalent, so the conversion is exact.

RFC-822-style log line

PHP date() D, d M Y H:i:s
Python strftime() %a, %d %b %Y %H:%M:%S

Short weekday/month names and zero-padded fields both map directly.

Ordinal day (partial conversion)

PHP date() l jS F Y
Python strftime() %A %B %Y

`j` (day without leading zero) and `S` (ordinal suffix) both have no strftime equivalent, so they're dropped and flagged as warnings — the day number is missing from the output entirely, leaving a double space.

Edge cases

Edge case

jS (day without leading zero + ordinal suffix) only partially converts: both j and S have no strftime equivalent, so the day number disappears from the output entirely — this is flagged with two separate warnings.

Edge case

Escaped PHP literals (e.g. \a) round-trip correctly through the conversion pipeline as literal text, including when the escaped character is itself a recognized PHP token.

References

  • PHP Manual — date() — checked 2026-07-29
  • Python docs — strftime() and strptime() format codes (v3.x) — checked 2026-07-29

Last verified 2026-07-29.