這是一個計算2000年01月01日起到指定日的天數的函數
(算頭也算尾)日期格式為:YYYY-MM-DD
// 計算從2000年01月01日開始到某日的天數
function cal_start2end($end_day,$start_day)
function cal_start2end($end_day,$start_day)
{
{
🎜>
$start_day=ereg_replace("-","",$start_day);
$end_day=ereg_replace("-","",$end_day);
if($end_day>=$start_day)
{ // 截止日期比起開始日期
if(substr($end_day,0,4)==substr($start_day,0,4)) {
if( is_int(substr($end_day,0,4)/4) )
$leap_day=29;
// //上一年
if {
// the same month
, }
其他
{
// switch (substr($end_day,4,2))
{ 地 休息;
案例中」02":
str($end_day,6,2) 31;
休息;
案例中"03":
) $leap_day 31;
$endday_from_newyear=substr( $end_day,6,2) 1 $leap_day 31*2;
🎜> $endday_from_newyear=substr($end_day,6,2) 1 $leap_day_from_newyear=substr($end_day,6,2) 1 $leap_day 31*230;
休息;
案例"06":
$endday_from_newyear=substr($end_day,6,2) 1 $leap_day 31*3 30;
休息;
案例"07":
$endday_from_newyear=substr($end_day,6, 休息;
天_from_newyear=substr($end_day,6, 2) 1 $leap_day 31*3 30*2;
🎜> $endday_from_newyear=substr($end_day,6,2) 1 $leap_day_from_newyear=substr($end_day,6,2) 1 $leap_day 31*2;
休息;
$endday_from_newyear=substr($end_day,6,2) 1 $leap_day 31*5 30*3;
案例"11":
地1 $leap_day 31*5 30*4;
> $endday_from_newyear=substr($end_day,6,2) 1 $leap_day 31*5 300*5 休息;
_from_startday=$endday_from_newyear;
}
return ($endday_from_? > {
// 不同的年份!
$differ_year=substr($end_day,0,4)-substr($start_day,0,4);
$how_int_4_floor=floor($differ_year/4) 1; // 向下取整
$how_int_4_ceil=ceil($differ_year/4) 1; // 向上取整
if($how_int_4_floor==$how_int_4_ceil)
$how_leap_year=$how_int_4_floor> $how_leap_year=$how_int_4_floor-1;
其他
$how_leap_year=$how_int_4_floor;
$how_noleap_year=$differ_year-$how_leap_year;
$differ_year2day=$how_noleap_year*365 $how_leap_year*366;
if( is_int(substr($end_day,0,4)/4) )
$leap_day=29; //閏年
else
$leap_day=28;
if(substr($end_day,4,2)==substr($start_day,4,2)) $endday_from_startday =$differ_year2day substr($end_day,4,2);
}
其他
{
// switch (substr($end_day,4,2))
{ 地 休息;
案例中」02":
str($end_day,6,2) 1 31;
休息;
$endday_from_newyear=substr($end_day,6,2) 1 $leap_day 31;
案例"04":
substr($end_day,6,2) 1 $leap_day 31*2;
5":
以30;
休息;
案例"06":
$endday_from_newyear=substr($end_day,6,2) 1 $leap_day 31*3 30;
休息;
案例"07" :
會 休息;
$endday_from_newyear=substr($end_day, 6,2) 1 $leap_day 31*3 30*2;
$endday_from_newyear=substr($end_day,6,2) 1 $leap_day_from_newyear=substr($end_day,6,2) 1 $leap_day 31*530* 2;
的休息下;
$endday_from_newyear=substr($end_day,6,2) 1 $leap_day 31*5 30*3;
案例"11":
地1 $leap_day 31*5 30*4;
> $endday_from_newyear=substr($end_day,6,2) 1 $leap_day 31*5 300*5 休息;
_from_startday=$endday_from_newyear $differ_year2day;
} //不同月結束
return🎜>return ($endday_from_startday);
} // 年末
} ///$0 >
$start_day="2000-01-01";
$end_day="2011-01-01";
echo "您輸入的是:". $end_day."
n";
$endday_from_startday=cal_start2end($end_day,$start_day);
echo "該日距離$start_day 共".$endday_from_startday." 天";🎜 >
? >
時間太少了,那個大蝦可以修改為計算任兩個日期之間的間隔最好! ! ! ! !
http://www.bkjia.com/PHPjc/316431.html
www.bkjia.com
true
http: //www.bkjia.com/PHPjc/316431.html
TechArticle