Re: [PHP] Formatting a MYSQL time
Here Frank, play with this you'll have to add a bit of code to select your time values, but it will start you down the road. I spent some time playing with this a couple of years ago, this is taken from a file with the grand name of junk.php! Miles Thompson // up here there's code to connect, choose dtabase and select some values. //The value fetched and stored in $dtAuctionStart is timestamp(14). Some messing about with dates br =br ? echo $dtAuctionStart, br; echo date (Y-m-d, $dtAuctionStart ), br; //$strDate = $dtAuctionStart ; echo dtAuctionStart : $dtAuctionStart; $year = substr ($dtAuctionStart, 0, 4); $month =substr( $dtAuctionStart, 4, 2 ); $day = substr ($dtAuctionStart, 6, 2 ); Echo dtAuctionStart in m-d -y : $month-$day-$year br; $workdate = getdate( $dtAuctionStart ); echo Workdate Year:, $workdate[year],br; ? Ereg Stuff br ==br ? if (ereg (([0-9]{4})([0-9]{1,2})([0-9]{1,2}), $dtAuctionStart, $regs)) { echo Auction Start: $regs[1]-$regs[2]-$regs[3] brbr; } else { echo Bad date format. br; } //echo gmdate (Y-m-d, time()), br; echo date (M-d-Y, mktime (0,0,0, $month, $day, $year)); // echo date (M-d-Y, mktime (0,0,0,12,32,1997)); echo brLocal date: br ; echo date (M d Y H:i:s, time()), br; echo date (M d Y H:i:s, time()), br; echo Greenwich date: br; echo gmdate (M d Y H:i:s, time()), br; echo gmdate (YmdHis, time()), br; ? At 11:21 AM 2/7/2002 -0600, Frank Miller wrote: 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 AM 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 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Formatting a MYSQL time
I would let mysql do the work: select *,date_format(dateofevent,%H:%i %p) as date_formatted from table... - Mark On Thu, 07 Feb 2002 11:21:13 -0600, Frank Miller wrote: 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 AM 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
RE: [PHP] Formatting a MYSQL time
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 [EMAIL PROTECTED] www.helpelf.com -Original Message- From: Frank Miller [mailto:[EMAIL PROTECTED]] Sent: Thursday, February 07, 2002 10:21 AM To: [EMAIL PROTECTED] 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 AM 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 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Formatting a MYSQL time
well, from what you show here you are trying to use a MYSQL timestamp format string in a UNIX Timestamp String. what you need to do is add add this to your select statement. SELECT UNIX_TIMESTAMP(replace with column name) From Table; you want to convert the MYSQL timestamp into a UNIX timestamp. then just through that into the date function and if should work. Jim Lucas www.bend.com - Original Message - From: Frank Miller [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Thursday, February 07, 2002 9:21 AM 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 AM 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 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Formatting a MYSQL time
On Thu, 2002-02-07 at 10:47, Kevin Stone wrote: 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. Minor correction: http://www.php.net/mktime Arguments may be left out in order from right to left; any arguments thus omitted will be set to the current value according to the local date and time. Torben $timestamp = mktime($hour, $min, $sec, $month, $day, $year); Hope this helps some. -- Kevin Stone [EMAIL PROTECTED] www.helpelf.com -- Torben Wilson [EMAIL PROTECTED] http://www.thebuttlesschaps.com http://www.hybrid17.com http://www.inflatableeye.com +1.604.709.0506 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Formatting a MYSQL time
Ah.. much appreciated. :) -Original Message- From: Lars Torben Wilson [mailto:[EMAIL PROTECTED]] On Behalf Of Lars Torben Wilson Sent: Thursday, February 07, 2002 12:43 PM To: Kevin Stone Cc: [EMAIL PROTECTED] Subject: RE: [PHP] Formatting a MYSQL time On Thu, 2002-02-07 at 10:47, Kevin Stone wrote: 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. Minor correction: http://www.php.net/mktime Arguments may be left out in order from right to left; any arguments thus omitted will be set to the current value according to the local date and time. Torben $timestamp = mktime($hour, $min, $sec, $month, $day, $year); Hope this helps some. -- Kevin Stone [EMAIL PROTECTED] www.helpelf.com -- Torben Wilson [EMAIL PROTECTED] http://www.thebuttlesschaps.com http://www.hybrid17.com http://www.inflatableeye.com +1.604.709.0506 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php