3v4l.org

run code in 300+ PHP versions simultaneously
<?php $year=2021; $month=7; $day=5; $index=-1; $period='day'; // strtotime test $dateString = $year . "-" . $month . "-" . $day . " -" . $index . " " . $period; $timestamp1 = strtotime("{$year}-{$month}-{$day} -{$index} {$period}"); // DateTime test $dateStamp = new \DateTime("{$year}-{$month}-{$day}"); $dateStamp->modify("-{$index} {$period}"); $timestamp2 = $dateStamp->getTimeStamp(); echo $dateString . PHP_EOL; echo "strtotime: " . $timestamp1 . PHP_EOL; echo "DateTime: " . $timestamp2;

preferences:
24.38 ms | 404 KiB | 5 Q