Current Location: Home> Latest Articles> How to Convert PHP Timestamps to Date Format - Practical Guide and Examples

How to Convert PHP Timestamps to Date Format - Practical Guide and Examples

M66 2025-07-11

How to Convert PHP Timestamps to Date Format

In PHP, converting a timestamp to a date is a common operation. Typically, this is done using the built-in date() function, which takes two parameters: a date format string and a timestamp, and returns the corresponding formatted date.

date() Function Syntax

date(format, timestamp)

Where:

  • format: The format string that specifies the returned date format.
  • timestamp: The Unix timestamp (the number of seconds since 1970-01-01 midnight UTC).

Common Date Format Specifiers

Here are some common date format specifiers:

SpecifierOutput Format
Y4-digit year
m2-digit month
d2-digit day
H2-digit hour (24-hour format)
i2-digit minute
s2-digit second

Practical Example

Here’s an example showing how to convert the timestamp 1658096324 into a date:

Code Example

$timestamp = 1658096324;
$date = date('Y-m-d H:i:s', $timestamp);
echo $date;

Output:

2022-07-19 14:58:44

Notes

When using the date() function, ensure that the timestamp is a valid Unix timestamp. If the timestamp is invalid, date() will return FALSE.

Conclusion

Through this guide, you now know how to convert timestamps to dates in PHP. We hope this article helps you. For more in-depth PHP tutorials, be sure to check out more related content.