In fact, there are many ways to compare two dates in PHP. The most common one I use is to use the strtotime function to convert the date into a number, and then add and subtract it. Let’s see an example below.
The code is as follows | Copy code | |||||||||||||||||||||||||||||||||||||||||||||
* Author: I don’t know who the author is * Date: 2008-4-13 * Function: Calculate the time difference between two dates * Remarks: Basically the program code has not been modified, only the writing has been standardized and comments have been made // Mancharo */ // Define the two dates to compare $Date_1="2008-7-15"; $Date_2="2006-7-14"; //Convert the date into an array to make a timestamp $Date_List_1=explode("-",$Date_1); $Date_List_2=explode("-",$Date_2);
$d1=mktime(0,0,0,$Date_List_1[1],$Date_List_1[2],$Date_List_1[0]); $d2=mktime(0,0,0,$Date_List_2[1],$Date_List_2[2],$Date_List_2[0]); // Date comparison $Days=round(($d1-$d2)/3600/24); //Output results echo "$Days days"; ?> Method 2
Previous article:php header() implementation program 404 error status_PHP tutorial
Next article:Solution to the problem that php functions cannot be called after registerPHPFunctions in XSLTProcessor_PHP Tutorial
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Latest Issues
Group MySQL results by ID for looping over
I have a table with flight data in mysql. I'm writing a php code that will group and displ...
From 2024-04-06 17:27:56
0
1
406
Related Topics
More>
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
|