php - How to get date from dateTime object -
i'm trying compare 2 dates - check difference between them in minutes. code is:
$first_date = new datetime($token->created_at); $first_date->format('y-m-d h:i:s'); $second_date = new datetime(); $second_date->format('y-m-d h:i:s'); $difference = $first_date->diff($second_date); $time_diff = $difference->format("%i"); var_dump($first_date); //i object object(datetime)#552 (3) { ["date"]=> string(26) "2016-04-21 10:00:00.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(3) "utc" }
how date datetime object, should compare 2 dates , check difference betwen them. thanks.
$difference_in_hours = (($second_date->gettimestamp() - $first_date->gettimestamp())/3600);
if difference between 2 dates greater 60 minutes:
if($difference_in_hours>1) { //if so, insert desired code here }
Comments
Post a Comment