PHP theorytheory 0/50 · 0%
Fundamentals · medium

35. Date & Time Handling

Working with DateTime.

The DateTime and DateTimeImmutable classes represent points in time and support formatting, arithmetic (via DateInterval), and timezone conversion. DateTimeImmutable is preferred in modern code because its methods return new instances instead of mutating state.

The date() function formats timestamps with format characters like 'Y-m-d H:i:s', while strtotime() parses human-readable date strings into Unix timestamps.

Check your understanding

  1. 1. Why prefer DateTimeImmutable over DateTime in modern code?

  2. 2. Which function converts a human-readable date string to a Unix timestamp?