Jump to content

Archived

This topic is now archived and is closed to further replies.

kevinmears

Formatting time

Recommended Posts

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,

Thanks

Kevin

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.