kevinmears Posted June 10, 2006 Share Posted June 10, 2006 Can someone help please. The web page gets a stored time from a table called bookings, the time is stored in the time data type in a sql table. The time is displayed on the web page using:$row1['time'];which comes up in the format: hh:mm:ss. However, I just want to display the hours and minutes with no seconds. Can someone help me out,ThanksKevin Link to comment https://forums.phpfreaks.com/topic/11667-formatting-time/ Share on other sites More sharing options...
poirot Posted June 10, 2006 Share Posted June 10, 2006 You can check this topic:[a href=\"http://www.phpfreaks.com/forums/index.php?showtopic=95404\" target=\"_blank\"]http://www.phpfreaks.com/forums/index.php?showtopic=95404[/a]MySQL can format the date using DATE_FORMAT Link to comment https://forums.phpfreaks.com/topic/11667-formatting-time/#findComment-44110 Share on other sites More sharing options...
mainewoods Posted June 10, 2006 Share Posted June 10, 2006 You say your date is stored in an sql table. I assume you mean a 'mysql' table. There is a problem with storage formats differences between php and mysql. When you retrieve a date/time value from mysql, first you will have to convert it using:[code]function convert_timestamp ($timestamp){ $parts = sscanf($timestamp, '%04u%02u%02u%02u%02u%02u'); $string = vsprintf('%04u-%02u-%02u %02u:%02u:%02u', $parts); return strtotime($string);}[/code]-then you want to use it like this:[code]$time = convert_timestamp($row1['time']);[/code]--then you use the php date funtion[code]echo date("format-string", $time);[/code][a href=\"http://us3.php.net/manual/en/function.date.php\" target=\"_blank\"]http://us3.php.net/manual/en/function.date.php[/a] Link to comment https://forums.phpfreaks.com/topic/11667-formatting-time/#findComment-44111 Share on other sites More sharing options...
poirot Posted June 10, 2006 Share Posted June 10, 2006 If you want to convert form a MySQL timestamp to UNIX you can use MySQL's built-in UNIX_TIMESTAMP or PHP's strtotime()[a href=\"http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html\" target=\"_blank\"]http://dev.mysql.com/doc/refman/5.0/en/dat...-functions.html[/a][a href=\"http://www.php.net/strtotime\" target=\"_blank\"]http://www.php.net/strtotime[/a] Link to comment https://forums.phpfreaks.com/topic/11667-formatting-time/#findComment-44114 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.