How to convert date to seconds in PHP

How to convert date to seconds in PHP

Posted by Luke Beeno on July 26, 2022

How to convert date to seconds in PHP

How to convert date to seconds in PHP

Posted by Luke Beeno on July 26, 2022

Convert date to seconds in php8:

Step 1. Make sure timestamp is in English date format

Step 2. Make timestamp or date a string

Step 3. pass string to be parsed in strtotime()

Here is a few examples

Timestamp:

$str = '2022-07-05 08:36:33';
$timestamp = strtotime($str);
var_dump($timestamp); //1657010193

Date:

$str = '05 July 2022 08:36:33';
$date = strtotime($str);
var_dump($date); //1657010193