RE: [PHP] Time formatting issues
[snip] 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? [/snip] Have a look at http://www.php.net/mktime -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Time formatting issues
Thank you, Jay, that is interesting. I am looking for the am / pm denomination, which I do not see in mktime() I am essentially trying to have the TIME type which is a 24 hour clock display instead as a 12 hour clock with am and pm. I AM A TOTAL NEWBIE, (2ND DAY ever) so if I misunderstood the answer, I am sorry! Melissa -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Time formatting issues
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? $time = '13:05:00'; list($hr, $min, $sec) = explode(':', $time); if ($hr > 12) { $new_time = ($hr - 12); $ampm = 'pm'; } elseif ($hr == 12) { $new_time = '12'; $ampm = 'pm'; } else { $new_time = $hr; $ampm = 'am'; } $new_time .= ':' . $min . ':' . $sec . ' ' . $ampm; pretty simple ;) (I'm sure someone will find a way to make this better but that should work :P). -- Postgresql & php tutorials http://www.designmagick.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Time formatting issues
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) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Time formatting issues
Thank you VERY much Jay, Chris and Gary! I tried the php code to change it and that worked Great, as Chris suggested I am about to see how it flies with changing the SQL DB directly as Gary suggested. I might even just ADD a new DB field for the new format... The mktime function looks VERY interesting, but confusing to a newbie... That will be next on my list of things to try. Melissa -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Time formatting issues
Melissa W. Dickens wrote: Thank you VERY much Jay, Chris and Gary! I tried the php code to change it and that worked Great, as Chris suggested I am about to see how it flies with changing the SQL DB directly as Gary suggested. I might even just ADD a new DB field for the new format... The mktime function looks VERY interesting, but confusing to a newbie... That will be next on my list of things to try. Melissa No need to create a new field just for another format. If you are using mysql 5 you can create a view. mysql> create view view_name as select DATE_FORMAT(time_column, '%h:%i:%s %p') as time from your_table; Query OK, 0 rows affected (0.00 sec) mysql> select * from view_name; +-+ | time| +-+ | 12:45:41 PM | +-+ 1 row in set (0.00 sec) This way you're not updating multiple columns with the same data formated differently. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Time formatting issues
Melissa W. Dickens [EMAIL PROTECTED] 770-667-8933 843-838-7388 -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Sent: Monday, July 16, 2007 12:50 PM To: Melissa W. Dickens Hmm... Another reason to upgrade! We are running version 4 something or other! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Time formatting issues
The date_format function of MySQL should work for time as well... What are the errors? What did you use for the time format? On Sat, July 14, 2007 8:27 am, 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... > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > -- Some people have a "gift" link here. Know what I want? I want you to buy a CD from some indie artist. http://cdbaby.com/browse/from/lynch Yeah, I get a buck. So? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php