Check interval between datetimes in PHP

后端 未结 3 547
情歌与酒
情歌与酒 2021-01-28 13:33

I have a field in database that has type of datetime in which I add time when user visit a page. When user again comes I want to check the interval between his first visit and c

3条回答
  •  情深已故
    2021-01-28 14:23

    If you have PHP >= 5.3 you can use DateTime objects and functions:

    $visit = DateTime::createFromFormat('Y-m-d H:i:s', '2011-03-04 00:25:01');
    $now = new DateTime("now");
    
    $diff = $now->diff($visit);
    

提交回复
热议问题