-2

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
pramudityad
  • 57
  • 1
  • 8

3 Answers3

1

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'));
Sajeeb Ahamed
  • 6,070
  • 2
  • 21
  • 30
0

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;
Alok Mali
  • 2,821
  • 2
  • 16
  • 32
-1

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')
    }
Majid Ahmadi
  • 127
  • 5