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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.