RE: [PHP] Formatting a MYSQL time

From: Date: Thu, 07 Feb 2002 18:47:17 +0000
Subject: RE: [PHP] Formatting a MYSQL time
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-83891@lists.php.net to get a copy of this message
Unless the $eventdate coming being pulled from your database a bonified Unix timestamp the date() function will not work. I don't like MySQL functions so I've always used $timestamp = mktime() to create the timestamp. Then plug that value into a field defined as INT(14). Use $eventdate = date("g:i a", $timestamp) to convert the timestamp into the desired English format. The mktime() function can also be used to convert from English time back into a timestamp.. but it has kind of a weird format. It takes six parameters and if you choose to use them they are all required. $timestamp = mktime($hour, $min, $sec, $month, $day, $year); Hope this helps some. -- Kevin Stone Kevin@helpelf.com www.helpelf.com > -----Original Message----- > From: Frank Miller [mailto:frank.miller@tamut.edu] > Sent: Thursday, February 07, 2002 10:21 AM > To: php-general@lists.php.net > Subject: [PHP] Formatting a MYSQL time > > Hello, > > Since I'm the only one who uses php at work I run into a > little problem and was hoping maybe someone could help me. I've set up a > Mysql database that has an event time. I've set the field in the table > as: eventtime time DEFAULT 00:00:00. > When I go to print the eventtime I'm pulling it out of Mysql with the > following code snippet > > while ($row = mysql_fetch_array($result)) { > $dateofevent = $row["dateofevent"]; > $sponsor = $row["sponsor"]; > $location = $row["location"]; > $eventtime = $row["eventtime"]; > $contact = $row["contact"]; > > All of this works. I connect to Mysql and pull out the data. > > Then I'm formatting $eventtime with $etime = date("g:i a", $eventtime); > > The problem is that when I print $etime in an html table all I get is 6:00 > pm for all the events. When I print $eventtime I get the correct time > that > is stored in Mysql. My question is am I doing this correctly or do I need > to use another function to format a mysql time. > > Thanks in advance. > > Frank Miller > Computer Specialist and Webmaster > Technology and Distance Education > Texas A&M University-Texarkana > 2600 North Robison Rd > Texarkana, Texas 75501 > > Phone: 903-223-3156 > Fax: 903-223-3139 > Office: 165 > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php

« previous php.general (#83891) next »