Reply to Using PHP with MySQL Datetime

Your name:

Reply:


Posted by Brandon on 01/16/07 05:02

I'm using PHP with MySQL 4.x and was having trouble converting a
datetime from MySQL into a formatted string until I ran across this
solution that converts a YYYY-MM-DD HH:MM:SS string into a Unix-style
timestamp and then formats it.

$timestamp = "2005-04-06 15:43:34";
$time = strtotime($timestamp);
print date('Y-m-d \a\t H:i', $time)."\n";

However, it seems kind of counter productive. After all, aren't people
(and RDBMs like MySQL) getting away from Unix timestamps for the a
reason? I don't necessarily think that my code will last until the
2038 timestamp rollover but I would rather avoid timestamps if possible
and am surprised that PHP doesn't seem to offer a better solution -
like parsing the string into some sort of date object or array, and
then formatting THAT into the desired string. Is there such a thing
right now?

It looks like date_parse() is a step in the right direction
(http://php.net/manual/en/function.date-parse.php) but it looks like it
is not available in a snapshot release and that's only half of the
equation anyway. I could always write my own function to do what I am
after but I would like to use something built in if possible. Any
ideas?

-Brandon

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация