View Full Version : Why is it that...

06-16-2006, 05:42 PM
now php is a great language and it has loads of really useful functions, particularly date functions - why isnt there any php functions to convert a mysql date/date-time into a unix timestamp so it can be formatted like a normal date?
The code behind the process isnt difficult... so why isnt it there?
In 5 versions of php I cant believe no-one has thought of it - so there must be a reason for it.

06-16-2006, 06:37 PM
mysql also has many useful functions, http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html#id2716133

you may also want to read about mysql's date_format function.

06-16-2006, 07:47 PM
that assumes the date is coming from an sql database ;)

06-16-2006, 08:18 PM
well, obviously but you asked about mysql not any other database system.

06-16-2006, 08:35 PM
In the situation where you have a dump from a mysql database (that you have no access to yourself) I can see a PHP function being handy...
(speaking nicely to the people who provide the dump and getting it in the format you want would be better though...)

Kid Charming
06-16-2006, 11:12 PM
strtotime() (http://us2.php.net/manual/en/function.strtotime.php) accepts MySQL-formatted dates.

06-17-2006, 02:08 PM
strtotime() (http://us2.php.net/manual/en/function.strtotime.php) accepts MySQL-formatted dates.

It does?! Bonus! I tried to read the document about the formats it accepts but it made my head spin.

The 'mysql date format' is just the IS0 8601 international date format. Our data sources use it because in travel it is particularly important to have a standard date format. I simply called it the mysql date format because more people would know what that was than would understand ISO8601.