Created
July 22, 2013 06:17
-
-
Save WenLiangTseng/6051657 to your computer and use it in GitHub Desktop.
PHP計算兩個日期之間的天數
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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