Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save WenLiangTseng/6051657 to your computer and use it in GitHub Desktop.
Save WenLiangTseng/6051657 to your computer and use it in GitHub Desktop.
PHP計算兩個日期之間的天數
<?php
//----- 計算兩個日期之間的天數 -----//
$startTimeStamp = strtotime("2011/07/01");
$endTimeStamp = strtotime("2011/07/17");
$timeDiff = abs($endTimeStamp - $startTimeStamp);
$numberDays = $timeDiff/86400; // 86400 seconds in one day
// and you might want to convert to integer
$numberDays = intval($numberDays);
//----- 計算從某個時間到目前為止的天數 -----//
$today = date('Y/m/d'); //取得今天的日期
$startTimeStamp = strtotime("2012/09/09");
$endTimeStamp = strtotime($today);
$timeDiff = abs($endTimeStamp - $startTimeStamp);
$numberDays = $timeDiff/86400; // 86400 seconds in one day
// and you might want to convert to integer
$numberDays = intval($numberDays);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment