PHP Format Any Time/Date for MySQL
April 20th, 2005 Many people find the act of formatting a date or time for input into a MySQL database tedious. It's actually very simple. Here is a function that will take a timestamp value such as time() or a human readable string and format it for MySQL. MySQL format is: 'YYYY-MM-DD HH:MM:SS'
The output of this little script would look something like:
2005-04-20 21:54:00 2000-09-10 04:30:00 2000-09-15 00:00:00
[code lang="php"]2008-08-20 01:53:13
2000-09-10 04:30:00
2008-08-21 00:00:00
[/code]
Categories
Popular Posts
RSS Feeds
Archives
September 29th, 2007 at 12:13 pm
strtotime between php4 and php5 behavior differently; also the way older mysql stores datetime/timestamp (14) vs the new format YYYY-mm-dd HH:ii:ss, will cause further confusion if using strtotime. i would stay away from it unless i was sure the platform im developing on has the newest mysql and php
September 29th, 2007 at 12:39 pm
I did not know that. I wrote this using PHP 4 and MySQL 4 some time ago. I'll look into that. Let's call this a simplifies solution for smaller-scale projects where as you mentioned, you know the behavior of the PHP and MySQL versions being used.