View Full Version : formatting time that was VARCHAR

08-22-2007, 04:37 AM
My end result is that the date and time displayed on the page is like:

Aug, 21, 2007 6:43 pm

The problem is that the date and time is being sent and stored as VARCHAR in the format of:

18:44:01 Aug 21, 2007 PDT

I have gotten as far as:

SELECT STR_TO_DATE(date_completed,'%H:%i:%s %b %e, %Y') as mydate

Now I have been really stuck on how to get it to the desired format. I have tried the following but am getting a totally wrong output with a year of 1970:

$compDate = date('F Y h:i:s A' ,$rOrders['mydate']);
echo $compDate;

What am I doing wrong?

08-22-2007, 05:21 AM
This may sound like a smart aleck answer but you should just bite the bullet and convert your column to a datetime type field. All your formatting problems will go away and your life will be pure bliss forever.

Len Whistler
08-22-2007, 06:55 AM
How about exploding it into space separated values? 18:44:01 Aug 21, 2007 PDT

Becomes an array with 5 elements. 18:44:01 | Aug | 21, | 2007 | PDT

08-22-2007, 10:49 AM
the date you're passing in isnt a timestamp. Try using strtotime() on the value that comes out of the db to convert it into a timestamp before passing it into the date() function