Jump to content

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


tskweb
 Share

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

Link to comment
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();

 

Kevin

Link to comment
Share on other sites

This thread is more than a year old. Are you sure you have something important to add to it?

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • 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.