Calculates the number of days from January 01, 2000 to a specified day

Source: Internet
Author: User

This is a function that calculates the number of days from January 01, 2000 to a specified day
<br>
(Calculate head also count tail) date format is: YYYY-MM-DD
<br>


<?php
Calculate the number of days from January 01, 2000 to one 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;

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

Tags Index: