- time: documentation ( source)
- date: documentation ( source)
<?php
function date_to_unix($date){
// converts 20140526 - 1401062400
$date = DateTime::createFromFormat('Ymd', $date);
return (int) $date->format('U');
}
function unix_to_date($unix){
// converts 1401062400 - 20140526
$date = DateTime::createFromFormat('U', $unix);
return (int) $date->format('Ymd');
}
$date = date("Ymd");
echo "date $date\n"; // date 20140525
$time = time();
echo "time $time\n"; // time 1401069030
$unix = date_to_unix($date);
echo "unix $unix\n"; // unix 1401069030
$date = unix_to_date($unix);
echo "date $date\n"; // date 20140526