This is a function that calculates the number of days from January 01, 2000 to a specified day
(end of calculation) date format: YYYY-MM-DD
Calculate the number of days from January 01, 2000 to a 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)
{//Due date is greater than start date
if (substr ($end _day,0,4) ==substr ($start _day,0,4))
{
if (Is_int (substr ($end _day,0,4)/4)
$leap _day=29; Leap year
Else
$leap _day=28;
Same year
if (substr ($end _day,4,2) ==substr ($start _day,4,2))
{
The same month
$endday _from_startday= $end _day-$start _day+1;
}
Else
{
Not same month
Switch (substr ($end _day,4,2))
{
Case "01":
$endday _from_newyear=substr ($end _day,6,2) +1;
Break
Case "02":
$endday _from_newyear=substr ($end _day,6,2) +31;
Break
Case "03":
$endday _from_newyear=substr ($end _day,6,2) + $leap _day+31;
Break
Case "04":
$endday _from_newyear=substr ($end _day,6,2) +1+ $leap _day+31*2;
Break
Case "05":
$endday _from_newyear=substr ($end _day,6,2) +1+ $leap _day+31*2+30;
Break
Case "06":
$endday _from_newyear=substr ($end _day,6,2) +1+ $leap _day+31*3+30;
Break
Case "07":
$endday _from_newyear=substr ($end _day,6,2) +1+ $leap _day+31*2+30*2;
Break
Case "08":
$endday _from_newyear=substr ($end _day,6,2) +1+ $leap _day+31*3+30*2;
Break
Case "09":
$endday _from_newyear=substr ($end _day,6,2) +1+ $leap _day+31*5+30*2;
Break
Case "10":
$endday _from_newyear=substr ($end _day,6,2) +1+ $leap _day+31*5+30*3;
Break
Case "11":
$endday _from_newyear=substr ($end _day,6,2) +1+ $leap _day+31*5+30*4;
Break
Case "12":
$endday _from_newyear=substr ($end _day,6,2) +1+ $leap _day+31*5+30*5;
Break
}
$endday _from_startday= $endday _from_newyear;
}
Return ($endday _from_startday);
}
Else
{
Different years!
$differ _year=substr ($end _day,0,4)-substr ($start _day,0,4);
$how _int_4_floor=floor ($differ _year/4) +1; Rounding down
$how _int_4_ceil=ceil ($differ _year/4) +1; Rounding up
if ($how _int_4_floor== $how _int_4_ceil)
$how _leap_year= $how _int_4_floor-1;
Else
$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; Leap year
Else
$leap _day=28;
if (substr ($end _day,4,2) ==substr ($start _day,4,2))
{
The same month
$endday _from_startday= $differ _year2day+ substr ($end _day,4,2);
}
Else
{
Not same month
Switch (substr ($end _day,4,2))
{
Case "01":
$endday _from_newyear=substr ($end _day,6,2) +1;
Break
Case "02":
$endday _from_newyear=substr ($end _day,6,2) +1+31;
Break
Case "03":
$endday _from_newyear=substr ($end _day,6,2) +1+ $leap _day+31;
Break
Case "04":
$endday _from_newyear=substr ($end _day,6,2) +1+ $leap _day+31*2;
Break
Case "05":
$endday _from_newyear=substr ($end _day,6,2) +1+ $leap _day+31*2+30;
Break
Case "06":
$endday _from_newyear=substr ($end _day,6,2) +1+ $leap _day+31*3+30;
Break
Case "07":
$endday _from_newyear=substr ($end _day,6,2) +1+ $leap _day+31*2+30*2;
Break
Case "08":
$endday _from_newyear=substr ($end _day,6,2) +1+ $leap _day+31*3+30*2;
Break
Case "09":
$endday _from_newyear=substr ($end _day,6,2) +1+ $leap _day+31*5+30*2;
Break
Case "10":
$endday _from_newyear=substr ($end _day,6,2) +1+ $leap _day+31*5+30*3;
Break
Case "11":
$endday _from_newyear=substr ($end _day,6,2) +1+ $leap _day+31*5+30*4;
Break
Case "12":
$endday _from_newyear=substr ($end _day,6,2) +1+ $leap _day+31*5+30*5;
Break
}//end of Switch
$endday _from_startday= $endday _from_newyear+ $differ _year2day;
}//end of not same month
Return ($endday _from_startday);
}//end of year
}//end of $end _day>= $start _day
}//end of function
$start _day= "2000-01-01";
$end _day= "2011-01-01";
echo "You entered:". $end _day. "
\ n ";
$endday _from_startday=cal_start2end ($end _day, $start _day);
echo "The day distance $start_day". $endday _from_startday. "Day";
?>
The time is too little, that prawn can be modified to calculate the interval between any two dates best!!!!!
The above describes the 2000 Nobel Prize for Literature to calculate the number of days from January 01, 2000 to a specified date, including the 2000 Nobel Prize for Literature, I hope to be interested in PHP tutorial friends helpful.