php: datetime() difference between 2 datetime with 2 variables

前端 未结 5 1925

I have in my database 4 columns which are:

Date_in | Time_in | Date_out | Time_out

Date_in and Time_in belong together (e.g., 2013-02-18 13

5条回答
  •  执念已碎
    2020-12-20 05:04

    You don't need quotes if you want to evaluate the variables content. In this case, you only need them to create a separation between date and time:

    $start_time = new DateTime($list['date_in']." ".$list['time_in']);
    $since_start = $start_time->diff(new DateTime($list['date_out']." ".$list['time_out']));
    

    I am using the dot . in order to concatenate variables with an string, in this case the string is a white space.

    You can read more about concatenation in the documentation.

提交回复
热议问题