$date = new DateTime('2021-10-01'); $date->setTime(14, 30, 0); echo $date->format('Y-m-d H:i:s');
$date = new DateTime(); $date->modify('+1 day'); echo $date->format('Y-m-d');
$date = DateTime::createFromFormat('Y-m-d H:i:s', '2021-10-01 14:30:00'); echo $date->format('Y-m-d');This code creates a new DateTime instance from the string "2021-10-01 14:30:00" using the format "Y-m-d H:i:s" and formats it as "2021-10-01". PHP DateTime format is part of the PHP core library, so there is no need to install any external package or library.