tskweb Posted December 31, 2002 Share Posted December 31, 2002 I want to keep a datetime field in this format 00/00/0000 00:00:00 AM or PM menaing the data Im recieving looks like this 12/15/2002 10:14:58 PM How is this possible with MySQL The data comes from a text file that is dumped for me. I need it to be datetime so I can do rollups on it Thanks for any help here Link to comment https://forums.phpfreaks.com/topic/14-mysql-datetime-00000000-000000-p-is-this-possible/ Share on other sites More sharing options...
delamitri Posted January 8, 2003 Share Posted January 8, 2003 The only way is to use a function to format and unformat the date when reading and writing to a mysql date field. for instance if I had the date from a form as 08.01.2003 (UK style), and wanted to format it to the mysql date type: function format_date($fd_date) { // used to format the date to mysql date $datePart=explode(".", $fd_date); // datePart[0] will be day, [1] will be month, [2] will be year return $datePart[2]."-".$datePart[1]."-".$datePart[0]; } of course you have time in there as well, so may be worth exploding by the space to start with so you get the date, time and AM/PM split into a usable array, then build it up again after you have done the date formatting Just reverse the operation for unformat_date(); Kevin Link to comment https://forums.phpfreaks.com/topic/14-mysql-datetime-00000000-000000-p-is-this-possible/#findComment-69 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.