PHP DateTime object has no reflection!

For hours I've been banging my head against a wall trying to figure out why Drupal's date_make_date "wasn't working." I was always getting back an empty PHP DateTime object. I traced it back down to PHP's date_create. I suspected that there was no reflection capabilities, but searching against date_create really didn't yield me much.

Eventually I decided "let's just search up a level (date_make_date empty object)" and in seconds I came across this thread: http://drupal.org/node/514560. This is just proof to me that the Drupal community is super awesome.

Hope this saves other people a bunch of time. If you're trying to just see what time is stored in a PHP DateTime object, print_r won't work - pass it through a format() (date_format()) call first.

Please complete the code i

Please complete the code i think its not complete

The date_format function is

The date_format function is documented here: http://php.net/manual/en/function.date-format.php. It is an alias of a method call on the DateTime object. To use the function you have to use, for example:

$myDateTime->format('Y-m-d');

The string that you pass in to format() is like it is for the PHP date() function: http://www.php.net/manual/en/function.date.php.

Post new comment

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <h1> <h2> <h3> <h4> <h5> <h6> <img>
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • Lines and paragraphs break automatically.

More information about formatting options