Re: newbie date time question
| From: | David Nicholls | Date: | Wed, 22 Jun 2011 14:59:26 +0000 |
| Subject: | Re: newbie date time question | ||
| References: | 1 2 3 4 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-313641@lists.php.net to get a copy of this message | ||
OK, looks like I have fixed problem, using:
$format = 'd/m/Y g:i:s A';
$dt = date_create_from_format($format, $d[0]);
$dt2 = date('r', $dt->getTimestamp());
$data[] = array(strtotime($dt2), $d[1]);Not elegant but it gives me the date/time value. Thanks, Adam and Richard DN On 23/06/11 12:51 AM, Adam Balogh wrote:
$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. b3haThanks, 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 conversion10 $format = 'd/m/Y h:i:s A'; 11 $dt = DateTime::createFromFormat($**format, $d[0]); 12 echo $dt,"...";DN