Re: Time formatting issues

From: Date: Mon, 16 Jul 2007 08:25:14 +0000
Subject: Re: Time formatting issues
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-258894@lists.php.net to get a copy of this message
Melissa wrote:
I have a DB with a field type DATE (called TideDATE) and a field type TIME (one of which is called highFIRST) How can I format the time fields from displaying 00:00:00 (a 24 hour clock) to HH:MM am/pm format? The DATE function has all kinds of neat formatters, but I do not find any for TIME In DATE, I would say "g:i A" If I try it with a TIME field, I get errors! I HAVE NEVER USED A NEWSGROUP BEFORE, SO I HOPE I HAVE DONE THIS CORRECTLY... What type of database are you using? You can probably do this right in the database. If MySQL you can do the following:
select DATE_FORMAT(time_column, '%h:%i:%s %p') from your_table; Tests: mysql> select DATE_FORMAT('2007-07-16 14:19:00', '%h:%i:%s %p'); +---------------------------------------------------+ | DATE_FORMAT('2007-07-16 14:19:00', '%h:%i:%s %p') | +---------------------------------------------------+
| 02:19:00 PM                                       |
+---------------------------------------------------+ 1 row in set (0.00 sec) mysql> select DATE_FORMAT('2007-07-16 04:19:00', '%h:%i:%s %p'); +---------------------------------------------------+ | DATE_FORMAT('2007-07-16 04:19:00', '%h:%i:%s %p') | +---------------------------------------------------+
| 04:19:00 AM                                       |
+---------------------------------------------------+ 1 row in set (0.00 sec)

« previous php.general (#258894) next »