When you need to manipulate a unix timestamp like field (seconds since 1970-01-01) that may be greater than the drop dead date of 2038-01-19.
<?php
function secs2date($secs,$date)
{
if ($secs>2147472000) {
$date->setTimestamp(2147472000);
$s=$secs-2147472000;
$date->add(new DateInterval('PT'.$s.'S'));
}
else
$date->setTimestamp($secs);
}
function date2secs($date,$datebeg)
{
$diff = $datebeg->diff($date);
$secs=$diff->format('%a') * (60*60*24); $secs+=$diff->format('%h') * (60*60); $secs+=$diff->format('%i') * 60; $secs+=$diff->format('%s'); return $secs;
}
$datebeg = new DateTime('1970-01-01');
$date=new dateTime();
$secs=2017472000; secs2date($secs,$date);
$dt=$date->format('Y-m-d H:i:s');
echo $dt."<br>";
$sec2=date2secs($date,$datebeg);
echo '(1) ',$sec2,'***',$secs,'<br>';
$secs=2397472000; secs2date($secs,$date);
$dt=$date->format('Y-m-d H:i:s');
echo $dt."<br>";
$sec2=date2secs($date,$datebeg);
echo '(2) ',$sec2,'***',$secs,'<br>';
?>