将时间添加到 PHP 中的日期
Adding time to a date in PHP
我正在尝试将时间添加到 PHP 中的日期。
这是我的变量和值;
$start_date = 2021-09-02 00:00:00
$start_time = 16:56:00
我想要的结果是:
2021-09-0216:56:00
如果变量已经是日期时间类型:
$result = date_format( date_add($start_date, $start_time), 'Y-m-d H-i-s');
如果变量是字符串类型:
$result = str_replace('00:00:00', '', $start_date) . $start_time;
$start_time = 16:56:00;
$start_date = 2021-09-02 00:00:00;
//Remove time portion from datetime column
$start_date = date('Y-m-d', strtotime($start_date));
//Add start time to start date
$combined_date_and_time = $start_date . $start_time;
我正在尝试将时间添加到 PHP 中的日期。 这是我的变量和值;
$start_date = 2021-09-02 00:00:00
$start_time = 16:56:00
我想要的结果是:
2021-09-0216:56:00
如果变量已经是日期时间类型:
$result = date_format( date_add($start_date, $start_time), 'Y-m-d H-i-s');
如果变量是字符串类型:
$result = str_replace('00:00:00', '', $start_date) . $start_time;
$start_time = 16:56:00;
$start_date = 2021-09-02 00:00:00;
//Remove time portion from datetime column
$start_date = date('Y-m-d', strtotime($start_date));
//Add start time to start date
$combined_date_and_time = $start_date . $start_time;