PHP函数将转换日期时间转换为excel Number DATEVALUE转换

发布时间:2022-04-30 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了PHP函数将转换日期时间转换为excel Number DATEVALUE转换脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
我只想要一个 PHP函数将日期转换为excel数字格式.

例如:2013-11-01至41579

这是在Excel中执行此操作的方法

PHP函数将转换日期时间转换为excel Number DATEVALUE转换

PHP函数将转换日期时间转换为excel Number DATEVALUE转换

解决方法

找到了一种将UNIX时间戳转换为Excel日期的方法.

$date_time = "2013-11-01 00:00:00";
$date_time_plus_one = strtotime($date_time . ' +1 day');
$str_date = strtotime(date('Y-m-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>';

一天中的秒数:89900,在1899年12月30日到1970年1月1日之间的25569天.所以这是输出.

脚本宝典总结

以上是脚本宝典为你收集整理的PHP函数将转换日期时间转换为excel Number DATEVALUE转换全部内容,希望文章能够帮你解决PHP函数将转换日期时间转换为excel Number DATEVALUE转换所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。