Re: Convert 24hr to 12hr
| From: | Lars Torben Wilson | Date: | Wed, 06 Feb 2002 04:38:44 +0000 |
| Subject: | Re: Convert 24hr to 12hr | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-83672@lists.php.net to get a copy of this message | ||
On Tue, 2002-02-05 at 18:44, Gary wrote:
> Hello All,
> Can someone please RTFM me so I can convert MySQL 24 hour time to 12
> hour time.
> TIA
> gary
Use MySQL's date_format() function with the %r specifier in your query:
shanna% mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2401 to server version: 3.22.32-log
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> select date_format(now(), '%T');
+--------------------------+
| date_format(now(), '%T') |
+--------------------------+
| 20:17:30 |
+--------------------------+
1 row in set (0.00 sec)
mysql> select date_format(now(), '%r');
+--------------------------+
| date_format(now(), '%r') |
+--------------------------+
| 08:17:39 PM |
+--------------------------+
1 row in set (0.00 sec)
mysql> quit
Bye
shanna%
This is documented at:
http://www.mysql.com/doc/D/a/Date_and_time_functions.html
Your query would then be something like the following, assuming a table
named my_table and a date/time column named my_column:
select date_format(my_column, '%r') from my_table
Alternatively, select the date as a timestamp and feed it to strftime():
http://www.php.net/strftime
Hope this helps,
Torben
--
Torben Wilson <torben@php.net>
http://www.thebuttlesschaps.com
http://www.hybrid17.com
http://www.inflatableeye.com
+1.604.709.0506