i have list of date with format 'Y-m-d'
2020-04-01
2020-04-02
2020-04-03
...
how do i add "00:00:00" for each list
2020-04-01 00:00:00
2020-04-02 00:00:00
i have list of date with format 'Y-m-d'
2020-04-01
2020-04-02
2020-04-03
...
how do i add "00:00:00" for each list
2020-04-01 00:00:00
2020-04-02 00:00:00
You can use DateTime()
class converting a date string to a date-time object. And format it. You can try this.
$data = "2020-04-01";
$dateTime = new DateTime($data);
print_r($dateTime->format('Y-m-d H:i:s'));
You should convert original date to timestamp first then again create a date with expected format.
Like this -
$date = "2020-04-02";
$required_date = date("Y-m-d H:i:s", strtotime($date." 00:00:00"));
echo $required_date;
you can add with foreach array if you list is array or object
foreach($dates as $key => $date)
{
$dates[$key] = $date.' 00:00:00' ;
}
or you can use datetime
foreach($dates as $key => $date)
{
$datetime = new DateTime($date);
$dates[$key] = $datetime ->format('Y-m-d H:i:s')
}