Hey guys,

Using PHP I store a datetime in a mySQL table. I am trying to draw that out and reformat the time.

The datetime is contained within the array $user_data['6'] and the format in the mySQL table is set to datetime.

The error I'm getting is Call to a member function format() on a non-object

        $joindate = strtotime($user_data['6']);
        $joindate = $joindate->format('l F Y H:i:s');

Is there a way to get passed this?

1 Year
Discussion Span
Last Post by James_43

pritaeas has the easiest solution IMO.

However, take the time to read the PHP manual carefully: http://php.net/manual/en/function.strtotime.php

int strtotime ( string $time [, int $now = time() ] )

This means that the returned value is an int (integer).
It takes two parameters:
$time (a time string in a recognized format)
$now (an optional parameter - denoted by [, ], which takes an integer based on an actual timestamp - if not supplied, it defaults to the current timestamp - time())

So this:

$joindate = strtotime($user_data['6']);
$joindate = $joindate->format('l F Y H:i:s');

Just doesn't make sense. $joindate most likely has an integer as a value after the first line. You're trying to use it an an object - performing some format method on it - which obviously cannot exist on an integer.

An alternative method would be to use the DateTime object..

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.