求從2017-2-5 到2018-3-6 有多少天?用PHP寫一個通用函數來完成這個題目。
1 回答

手掌心
TA貢獻1942條經驗 獲得超3個贊
<?php
$start = '2017-2-5';
$end = '2018-3-6';
function calDate($start,$end){
$start_time = strtotime($start); // 獲得$start 的秒時間戳
$end_time = strtotime($end); // 獲得$end 的秒時間戳
return ($end_time - $start_time)/60/60/24; // 秒時間戳相減得到兩個日期相差的秒數,通過秒數計算天數
}
echo calDate($start,$end);
- 1 回答
- 0 關注
- 711 瀏覽
添加回答
舉報
0/150
提交
取消