0

I need to pull the date from the object below and nothing ($obj->date, $obj['date'], etc.) I've tried has worked. I'm not sure if what I'm searching for isn't correct, but I can't find anything in searches as to how to grab "2015-08-12 15:47:04".

Can someone tell me how to get it and describe what everything is called? Is it correct to say that I need to get the value of the first key from an object?

object(DateTime)#630 (3) {
  ["date"]=>
  string(19) "2015-08-12 15:47:04"
  ["timezone_type"]=>
  int(3)
  ["timezone"]=>
  string(3) "UTC"
}
AbraCadaver
  • 78,200
  • 7
  • 66
  • 87
Cofey
  • 11,144
  • 16
  • 52
  • 74

1 Answers1

1
<?php
$now = new DateTime(NULL);

echo $now->format("Y-m-d h:i:s");

see http://php.net/manual/en/datetime.format.php

also see related: Why can't I access DateTime->date in PHP's DateTime class? Is it a bug? and print_r() adds properties to DateTime objects

Community
  • 1
  • 1
Andy Ericksen
  • 121
  • 1
  • 4