🐘 PHP Beginner

What are PHP date and time functions?

Answer

PHP has comprehensive date/time functions. time() returns the current Unix timestamp (seconds since January 1, 1970 UTC). date($format, $timestamp) formats a timestamp — e.g., date("Y-m-d H:i:s") gives "2024-01-15 14:30:00". strtotime($str) converts a human-readable date string to a Unix timestamp. The modern, object-oriented approach uses the DateTime and DateTimeImmutable classes along with DateInterval and DateTimeZone — these handle timezone conversions, date arithmetic, and formatting more cleanly than procedural functions. Always store dates in UTC in the database and convert to user timezones only for display.