Setting the default timezone (otherwise, everything will be UTC)
date_default_timezone_set('America/New_York');
Creating a NOW timestamp as Object
$today=new DateTime();
echo $today->format('Y-m-d H:i:s');
Creating a NOW timestamp procedurally
$today = date_create(); echo date_format($today, 'Y-m-d H:i:s');
Time between two dates (not the cleanest way)
$this_date = (new DateTime()) -> getTimestamp(); //today
$other_date = strtotime('2020-07-14'); //some other date
//Result is in number of seconds, will need to be converted
$delta = $that_date-$this_date;
Quick code for time between two dates:
date_default_timezone_set('America/New_York');
$date_format='F jS, Y';
$this_date = (new DateTime()) -> getTimestamp(); //today
$that_date = strtotime("2020-07-07"); //random date mySQL format
$delta = $that_date-$this_date;
$delta = round($delta/60/60/24,1);
$that_date = date($date_format,$that_date);
if ($delta > 0) {
$result="
<p>
$that_date is $delta day(s) from today
</p>
" ;
echo $result;
} else {
$result="
<p>
$that_date was $delta day(s) ago
</p>
" ;
echo $result;;
}