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'));