Hi,
I'm not sure if this is a duplicate or not, but i couldnt find anything in the queues to exactly what i was experiencing straight away, sorry if it is.

when i try calling date_make_date() to generate a date object it returns an empty object.

i have tried multiple formats as following -


$date = date_make_date('2009-07-09 12:18:06', null, DATE_DATETIME);

$date = date_make_date('2009-07-09T12:18:06', DATE_ISO);

I have also tried with DATE_ARRAY. All these return a blank object :(

any ideas?

Comments

budda’s picture

Passing in an array for $date and a type of DATE_ARRAY would return a NULL according to the code:

<?php
  if (empty($date) || is_array($date)) {
    return NULL;
  }
?>
karens’s picture

Status: Active » Closed (works as designed)

It's not 'an empty object', that's the way the PHP date object works. You can't see anything in it, but it is valid. You can do things like:

print date_format($date, 'm/d/Y H:i');

And you will see that it holds a value.

cyberwolf’s picture

Status: Closed (works as designed) » Active

Hi there

I'm encountering the same issue.

Passing in $date as an array, and setting the $type to DATE_ARRAY:

$date = array(
  'year' => 2010,
  'month' => 6,
  'day' => 20,
  'hour' => 12,
  'minute' => 0,
  'second' => 0,
);

$date_object = date_make_date($date, 'Europe/Brussels', DATE_ARRAY);

$date_object is NULL now because of the line mentioned by budda.

Removing the is_array() check seems to solve the problem here.

cyberwolf’s picture

Status: Active » Needs review

I suggest just removing the is_array check, I don't see what's the use of it.

cyberwolf’s picture

A temporary workaround is using date_convert() instead of date_make_date().

$date_object = date_convert($date, DATE_ARRAY, DATE_OBJECT, date_default_timezone_name());
netsensei’s picture

I just noticed the same thing.

Trying to get this to work:

$date = date_make_date('1995-10-09T00:00', NULL, DATE_ISO);

returns me an empty object. I've also tried it with DATE_DATETIME. No dice.

damienmckenna’s picture

Issue summary: View changes
Status: Needs review » Closed (won't fix)

Unfortunately the D6 version of this module is no longer supported, but we appreciate the time you put into this. If this problem is relevant for D7 too, please reopen the issue. Thanks.