Re: newbie date time question
| From: | Adam Balogh | Date: | Wed, 22 Jun 2011 14:51:20 +0000 |
| Subject: | Re: newbie date time question | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-313640@lists.php.net to get a copy of this message | ||
$dt is an object as the error says, so you cant echo it, becouse its not a
string (it can be with __toString magic method, or use print_r/var_dump to
output your object). Try the format (
http://www.php.net/manual/en/datetime.format.php)
method on your $dt object.
On Wed, Jun 22, 2011 at 4:41 PM, David Nicholls <dcn@dcnicholls.com> wrote:
> On 23/06/11 12:23 AM, Adam Balogh wrote:
>
>> hi,
>>
>> you have a PM(/AM) in your date ($d[0]), so put an "A" (Uppercase Ante
>> meridiem and Post meridiem) format char to your $format variable.
>>
>> b3ha
>>
>
> Thanks, Adam. Tried that and it's now throwing an error:
>
> Catchable fatal error: Object of class DateTime could not be converted to
> string in <xxx.php> on line 12
>
> Line 12 follows the attempt at conversion
>
> 10 $format = 'd/m/Y h:i:s A';
> 11 $dt = DateTime::createFromFormat($**format, $d[0]);
> 12 echo $dt,"...";
>
> DN