Tags
Asked 3 years ago
9 Jun 2021
Views 225
steave

steave posted

DateTime with date without hours in php

DateTime with date without hours in php
ravi

ravi
answered Apr 26 '23 00:00

You can use the format () method of the DateTime class to output the date without the hours. Here's an example:



$date = new DateTime('2022-05-01 13:45:00');
echo $date->format('Y-m-d'); // Output: 2022-05-01

In the above example, we created a new DateTime object with the date 2022-05-01 13:45:00. Then, we used the format () method with the Y-m-d format to output the date without the hours.
Post Answer