Jump to content

Formatting time


kevinmears

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

Link to comment
https://forums.phpfreaks.com/topic/11667-formatting-time/
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]
Link to comment
https://forums.phpfreaks.com/topic/11667-formatting-time/#findComment-44111
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]
Link to comment
https://forums.phpfreaks.com/topic/11667-formatting-time/#findComment-44114
Share on other sites

Archived

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

×
×
  • Create New...

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.