Welcome to the Linux community forum, and interact with 2 million technical staff to enter the number of days for calculation of the difference between the given two dates using php: the calculation method is not just described below, but some of the more common methods: to calculate the difference between And :? Php $ startdatestrtotime ("2009-12-09"); $ enddatestrtoti
Welcome to the Linux community forum, interact with 2 million technical staff> enter the number of days for calculating the difference between the given two dates in php: the calculation method is not only described below, but some of the more common methods: to calculate the difference between And :? Php $ startdate = strtotime ("2009-12-09"); $ enddate = strtoti
Welcome to the Linux community forum and interact with 2 million technicians>
Use php to calculate the number of days for the given two dates:
The calculation method is not only described below, but also a common method:
To calculate the difference between and:
$ Startdate = strtotime ("2009-12-09 ");
$ Enddate = strtotime ("2009-12-05 ");
The above php time and date function strtotime has converted the string date into a timestamp, so that we only need to subtract the two values and then convert the second to the day. The comparison is simple, as shown below:
$ Days = maid ($ enddate-$ startdate)/3600/24 );
Echo $ days; // days indicates the number of days;
?>
The following describes another method:
The size of the two dates is determined above, and the program code for judging the birthday is as follows. The resulting $ n is the number of days of the birthday.
$ Birthday = "birthday ";
$ Birthday = preg_replace ('/\ d +/', Date ('y'), $ birthday, 1 );
$ D = 60*60*24;
$ N = floor (strtotime ($ birthday)-time ()/$ d );
$ N = $ n + 1;
In addition, if we compare the current time, we can use the time () function to obtain the current timestamp.
In the second case, there is a database, which is relatively easier! You can use a trigger for MSSQL! You can use the datediff () function to calculate the date difference!
If it is MYSQL, use the timestamp value of the two date fields. After calculation, you can get the number of days of difference. The method is similar to the above Code.