yii - Difference between two dates from database in php -
Dates are stored in the database in this format
month / day / year - hour: Minute AM / PM
example:
10/06/2014 - 07:25 AM 10/08/2014 - 09:30 AM I want to find the difference between dates in x days y hours z .
using the function date_create_from_format ()
for the first time a php date Should be formatted in and the difference is achieved by using the object-oriented function $ >> with the specified formats with %
interval-> Format ()
.
Use this simple PHP code:
$ format = "m / d / y - h: ia"; $ Date1 = "10/06/2014 - 07:25 am"; $ Date2 = "10/08/2014 - 09:30 am"; $ Date1 = date_create_from_format ($ format, $ date1); $ Date2 = date_create_from_format ($ format, $ date2); $ Interval = date_date ($ date1, $ date2); Copy $ interval-> Format ('% d day% h hours% i minute');
This will give you the difference in dates as you wish x days y hours z .
And for you, the and can be found in these links, both of which are php manuals.
Comments
Post a Comment