Jump to content


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

  • Please log in to reply
1 reply to this topic

#1 tskweb

  • New Members
  • Pip
  • Newbie
  • 1 posts
  • LocationPlano

Posted 31 December 2002 - 04:51 PM

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

#2 delamitri

  • New Members
  • Pip
  • Newbie
  • 7 posts
  • LocationUK

Posted 08 January 2003 - 04:21 PM

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


0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users