3

I am working on a php code as shown below:

echo "<pre>";print_r($episode);echo "</pre>";

The above php code displays the following o/p:

stdClass Object
(
    [air_date] => 2019-04-15 07:15:00
    [air_duration] => 9900
    [schedule_id] => 4220986
    [program_id] => 23
)

Now on doing print_r($episode->air_date); it displays the following o/p:

2019-04-15 07:15:00

Problem Statement:

I am wondering what changes I need to make here print_r($episode->air_date); so that it displays only date, not the time.

flash
  • 1,455
  • 11
  • 61
  • 132

3 Answers3

1

you can wrapper

echo date('Y-m-d', strtotime ($episode->air_date));
print_r(date('Y-m-d', strtotime ($episode->air_date)));
Şafak Çıplak
  • 889
  • 6
  • 12
1

If you're just looking to print, you could just print the substring from the beginning to the position of the first space:

print(substr($episode->air_date, 0, strpos($episode->air_date, ' ')));

Chris White
  • 1,068
  • 6
  • 11
0

Running the following code you get:

$date = "2019-04-15 07:15:00";
echo date('Y-m-d', strtotime($date));

output: 2019-04-15

This will return a false value:

$date = "2019-04-15 07:15:00";
echo date('Y-m-d', $date);

output: 1970-01-01

Oguzcan
  • 412
  • 6
  • 20