Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pull only specific json object field value in php? [duplicate]

Tags:

json

php

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.

like image 938
flash Avatar asked May 25 '26 21:05

flash


1 Answers

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, ' ')));

like image 191
Chris White Avatar answered May 27 '26 09:05

Chris White



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!