- strtotime: documentation ( source)
<?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;