string(19) "2003-07-01 1...">

PHP How to get a parameter from an object?

When I do var_dump() , I get this answer

 object(DateTime)#1 (3) { ["date"]=> string(19) "2003-07-01 13:38:43" ["timezone_type"]=> int(3) ["timezone"]=> string(11) "Asia/Muscat" } 

Please tell me how can I derive the date parameter from this object?

+4
source share
3 answers

you can just use

 echo $dateObject->date; 

Otherwise, consider the DateTime#format method

 echo $dateObject->format('Ymd H:i:s'); // => 2003-07-01 13:38:43 

This is slightly better because it allows you to format the output as you would like.

+2
source

I will look at the result of var_dump, you will see that you are dealing with an instance of the DateTime class:

object (DateTime) # 1 (3) {

Knowing this, you should go to the link to the PHP class and look at the documentation: http://php.net/manual/en/class.datetime.php

There you will find how to use this particular class. If you look at the list of methods, you will find the DateTime :: format method that you need. http://php.net/manual/en/datetime.format.php

+2
source

Try

 $datetime = new Datetime(); echo $datetime->format('Ymd H:i:s'); 

Take a look at http://php.net/manual/en/datetime.format.php

0
source

All Articles