Search

PHP date format tokens worth memorising (Y-m-d is not ISO 8601)

PHP date format tokens worth memorising (Y-m-d is not ISO 8601)

date('Y-m-d H:i:s') and Carbon::parse($input)->format('Y-m-d H:i:s') share one token table. Y is four-digit year, m zero-padded month, d zero-padded day, H 24-hour hour. c is ISO 8601 with timezone. r is RFC 2822. Y-m-d is a nice date and it is not ISO 8601, because it has no time and no offset.

Also Read: preg_match versus preg_match_all, and how to test without hanging PHP

Tokens that bite

i is minutes. m is month. Using m in a time string is how you log 2026-09-23 16:09:00 when you meant 16:47. h is 01–12 and needs a or A or you cannot tell morning from evening. U is a Unix timestamp; do not concatenate it with hyphens and call it a datetime.

Also Read: ^10.0 is not ~10.0: Composer caret versus tilde - Laravel

The PHP date format cheatsheet is a token table with a live Carbon::parse preview. Paste now, or a real ISO string, and a format, and copy the result. Use it when you are about to write a filename, a lastmod, or a cron log line.

Also Read: 220 billable days: turning a day rate into take-home pay

Scheduler logs and lastmod

A cron next-run list is only useful if the format matches what humans read in UTC. That is the overlap with the cron translator. Sitemap lastmod wants a real date, not F jS Y. If you are building slugs from a title plus a date, format the date first, then Str::slug the title, and join them with a hyphen you control.

Keep one canonical format per app for “when did this happen” and another for “what do we show”. Mixing them in the same column is how reports disagree by an hour twice a year.

Tags:
TWT Staff

TWT Staff

Writes about Programming, tech news, discuss programming topics for web developers (and Web designers), and talks about SEO tools and techniques

Your experience on this site will be improved by allowing cookies Cookie Policy