Date difference in PHP? -
I am trying to compare two dates in PHP and statistics show how many days are there apart? I am receiving a MySQL database on the first date and the second date is the current date. The date in the MySQL database looks like this "2010-01-21 15:21:46"
$ date1 = Date ("YMD", $ product ['hold_date']) $ date2 = date ("YMD");
How can I compare these two dates and just return the quantity of days?
Edit ------------- ------------------------- ------------------------- ------------------
This works:
$ date1 = date (strotom ('2009-12-25 15:21:46')); $ Date2 = time (); $ Sec references = $ date2 - $ date1; $ Day = floor ($ sec difference / 86400); Echo every day;
$ sec references = $ date2 - $ date1;
This is a second between date 2 and date 1. According to the future, depending on which more recent / future you have to reorder. If you want a positive number then it is definitely.
Or you can use it:
$ secondsDifference = abs ($ date2 - $ date1);
You can simple arithmetic to find the number of days
define ("SECONDS_IN_DAY", 60 * 60 * 24); $ Day = floor ($ SECOND difference / SECONDS_IN_DAY); // round-down // You can use CIL () to straighten it.
To obtain a MySQL date in a second format, use strtotime ()
$ time = strtotime ($ mysql_time);
Do this:
$ date1 = starttime ($ product ['hold_date']); $ Date2 = time ();
Comments
Post a Comment