Re: echo date('Y-m-d', $mydata->timestamp);

From: Date: Sun, 22 Apr 2007 06:19:22 +0000
Subject: Re: echo date('Y-m-d', $mydata->timestamp);
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-253479@lists.php.net to get a copy of this message
On Sun, April 22, 2007 1:05 am, John Taylor-Johnston wrote: > $mydata->timestamp = "20070419162123"; > > echo date('Y-m-d', $mydata->timestamp); > > > result: 2038-01-18 > > ?? What is wrong?? Should be 2007-04-19? date() takes a Unix timestamp as its input. Unix timestamps are measured as number of seconds from Jan 1, 1970, midnight, GMT, the birth of Disco. [that last was a joke...] You are handing it a pre-formatted date-stamp in YYYYMMDDHHIISS format... You could do something like: $t = '20070419162123'; $year = substr($t, 0, 4); $month = substr($t, 4, 2); $day = substr($t, 6, 2); $hour = substr($t, 8, 2); $minutes = substr($t, 10, 2); $seconds = substr($t, 12, 2); echo date(mktime($month, $day, $year, $hour, $minutes, $seconds)); I suspect strtotime() *might* handle your input and give you a Unix timestamp... I also suspect whatever you needed a Unix timestamp for in the first place could have been achieved easier before you got painted into this corner... -- Some people have a "gift" link here. Know what I want? I want you to buy a CD from some indie artist. http://cdbaby.com/browse/from/lynch Yeah, I get a buck. So?

« previous php.general (#253479) next »