Jump to content


This topic is now archived and is closed to further replies.


MySQL DATETIME 00/00/0000 00:00:00 %p? Is this possible

Recommended Posts

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

Share this post

Link to post
Share on other sites

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();



Share this post

Link to post
Share on other sites

  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.