Ec (2); returns the difference between two dates & lt ;? Php $ time1 & nbsp; & quot; & nbsp; 11:49:59 & quot; first time $ time2 & nbsp; & quot; 2007-5-5 & nbsp; 12:53:28 & quot; second time $ t1 & nbsp; strtotime ($ time1); $ t2 & nbsp; script ec (2); script
Returns the difference between two dates.
$ Time1 = "11:49:59"; // The First Time
$ Time2 = "2007-5-5 12:53:28"; // second time
$ T1 = strtotime ($ time1 );
$ T2 = strtotime ($ time2 );
$ T12 = abs ($ t1-$ t2 );
$ Start = 0;
$ String = "two time differences :";
$ Y = floor ($ t12/(3600*24*360 ));
If ($ start | $ y)
{
$ Start = 1;
$ T12-= $ y x 3600*24*360;
$ String. = $ y. "year ";
}
$ M = floor ($ t12/(3600*24*31 ));
If ($ start | $ m)
{
$ Start = 1;
$ T12-= $ m x 3600*24*31;
$ String. = $ m. "month ";
}
$ D = floor ($ t12/(3600*24 ));
If ($ start | $ d)
{
$ Start = 1;
$ T12-= $ d * 3600*24;
$ String. = $ d. "day ";
}
$ H = floor ($ t12/(3600 ));
If ($ start | $ h)
{
$ Start = 1;
$ T12-= $ h * 3600;
$ String. = $ h. "Hour ";
}
$ S = floor ($ t12/(60 ));
If ($ start | $ s)
{
$ Start = 1;
$ T12-= $ s * 60;
$ String. = $ s. "Minute ";
}
$ String. = "{$ t12} seconds ";
Echo $ string;
?>
This is a function for finding any time difference.
# Author: xianle
# Function: Obtain the time difference between any time and the current time
Function QueryDays ($ datestr ){
# Formatting time
$ Da = preg_split ("/(-| :)/I", $ datestr );
$ Nowyear = date ("Y ");
$ Nowmon = date ("n ");
$ Nowday = date ("d ");
$ Nowtimes = mktime (0, 0, 0, $ nowmon, $ nowday, $ nowyear );
$ Pdtimes = mktime (, 0, $ nowmon, $ nowday, $ nowyear-1 );
$ Bjtimes = mktime (0, 0, $ da [1], $ da [2], $ da [0]);
# Determine whether the given time is within one year
If ($ bjtimes >=$ pdtimes and $ bjtimes <= $ nowtimes ){
Return (floor (strftime ("% j", mktime (0, 0, 0, $ nowmon, $ nowday, $ nowyear)-mktime ($ da [3], $ da [4], $ da [5], $ da [1], $ da [2], $ da [0]);
} Else {
$ Loop = $ nowyear-$ da [0];
$ Totaldays = (floor (strftime ("% j", mktime (, 0, $ nowmon, $ nowday, $ nowyear)-mktime (, 1, $ nowyear ))));
For ($ I = 1; $ I <= $ loop; $ I ++ ){
For ($ j = 12; $ j> = 1; $ j --){
If ($ da [0] ==$ nowyear-$ I and $ da [1] === j ){
$ Days = MonDays ($ nowyear-$ I, $ j );
Return $ totaldays + = $ days-$ da [2];
Break;
} Else {
$ Days = MonDays ($ nowyear-$ I, $ j );
$ Totaldays + = $ days;
} // End else
} // End
} // End
} // End else
} // End function
# Number of days for obtaining the monthly score
Function MonDays ($ year, $ month ){
Switch ($ month ){
Case "1 ":
Case "3 ":
Case "5 ":
Case "7 ":
Case "8 ":
Case "10 ":
Case "12": $ days = 31; break;
Case "4 ":
Case "6 ":
Case "9 ":
Case "11": $ days = 30; break;
Case "2 ":
If (checkdate ($ month, 29, $ year )){
$ Days = 29;
} Else {
$ Days = 28;
} // End else
Break;
} // End switch
Return $ days;
} // End function
$ Datestr = "9:47:20 ";
Echo QueryDays ($ datestr );
?>