Convert Datetime String to Timestamp in PHP

Do you ever need to convert a datetime string into a timestamp in PHP? With these snippets, you’ll be able to take any datetime string and turn it into a timestamp. This can come in handy when working with databases or logs, for example.

The following code snippet can be used to convert a datetime string to a timestamp in PHP:

$datetime = '2019-01-01 12:00:00';
$timestamp = strtotime($datetime);
echo $timestamp; //1546344000

//current timestamp
print strtotime(date('Y-m-d H:i:s'));

By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.

Close