convert datetime format

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
playwright
Forum Newbie
Posts: 20
Joined: Wed Jun 02, 2010 6:11 pm

convert datetime format

Post by playwright »

I have multiple datetimes. The format is dd-mm-yy, hh:mm. I want to insert it into a table using mysql. However mysql format is yy-mm-dd, hh:mm:ss. How can i do it and what type should i use (datetime?timestamp?).
Thanks for your help!!
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: convert datetime format

Post by AbraCadaver »

You probably want a four digit year, and use H for 24 hour time or h for 12 hour:

Code: Select all

$new_date = date('Y-m-d h:i:s', strtotime($old_date));
datetime or timestamp depends on what you need. You can read the differences here: http://dev.mysql.com/doc/refman/5.1/en/datetime.html
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Post Reply