Current Unix Timestamp SECONDS SINCE JAN 01 1970

Current UTC Time
2025-08-20
Convert Datetime to Unix Timestamp in PHP

How to convert Datetime to Unix timestamp in PHP

🎈 🎈 🎈
+1

    $timestamp = strtotime('2020-04-15 08:30:45');
    echo "Unix Timestamp: " . $timestamp;            
        

Output:
Unix Timestamp: 1042364180
Example only. There may be multiple ways to perform this operation.

Code Explanation

This PHP uses the strtotime() function to parse a human-readable date string and convert it directly into a Unix timestamp<> By using strtotime() the number of seconds that have elapsed since January 1, 1970, 00:00:00 UTC is returned, effectively converting the provided date into a Unix timestamp.


Other useful PHP date functions

Function Description Example
date() Formats a local date and time based on a given format string. date('Y-m-d H:i:s') returns 2024-08-28 12:34:56
time() Returns the current Unix timestamp (number of seconds since January 1, 1970). time() returns 1693227296
strtotime() Parses an English textual datetime description into a Unix timestamp. strtotime('2024-08-28 12:34:56') returns 1693227296
mktime() Returns the Unix timestamp for a date with specific time components (hour, minute, second, month, day, year). mktime(12, 34, 56, 8, 28, 2024) returns 1693227296
getdate() Returns an associative array with information about the current date/time or a given timestamp. getdate(1693227296) returns array with date components
gmdate() Formats a GMT/UTC date and time based on a given format string. gmdate('Y-m-d H:i:s', 1693227296) returns 2024-08-28 12:34:56
DateTime::createFromFormat() Creates a new DateTime object from a specified format. DateTime::createFromFormat('Y-m-d', '2024-08-28') returns DateTime object
DateTime::format() Formats a DateTime object according to a given format string. $datetime->format('Y-m-d H:i:s') returns 2024-08-28 12:34:56
DateTime::getTimestamp() Returns the Unix timestamp of a DateTime object. $datetime->getTimestamp() returns 1693227296
DateTime::setTimestamp() Sets the date and time based on a Unix timestamp. $datetime->setTimestamp(1693227296) sets the date/time to 2024-08-28 12:34:56
Current Unix Timestamp SECONDS SINCE JAN 01 1970

Current UTC Time
2025-08-20
Ad Banner Placeholder
Ad Banner Placeholder
Ad Banner Placeholder
Ad Banner Placeholder