用于将date时间转换为Excel的PHP函数Number DATEVALUE转换
我只是想要一个PHP函数将date转换为Excel数字格式。
例如: 2013-11-01至41579
这是在Excel中执行的方法
我find了一种将Unix时间戳转换为Exceldate的方法。
$date_time = "2013-11-01 00:00:00"; $date_time_plus_one = strtotime($date_time . ' +1 day'); $str_date = strtotime(date('Ym-d', $date_time_plus_one)); $excel_date = intval(25569 + $str_date / 86400); echo 'php actual date time : ' . $date_time . '<br>'; echo 'add one day : ' . $date_time_plus_one . '<br>'; echo 'excel Number DATEVALUE : ' . $excel_date . '<br>';
一天中的秒数:86400,1899年12月30日至1970年1月1日的25569天。所以这是输出。
php实际date时间:2013-11-01 00:00:00
添加一天:1383330600
excel号码DATEVALUE:41579
你可以把时间变成像这样的string。 每个date都是独一无二的,你也可以按顺序排列
$month = date("F"); $date = date("d"); $year = date("Y"); $timestamp = strtotime($month . " " . $date . " " . $year);