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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux