View Full Version : Formatting time?

07-30-2007, 04:12 PM
I have this code which formats the date from 2007 07 30 to 30th july, 2007

$timestamp=strtotime($row['today_inSQL'].' '.$row['time_inSQL']);
$formated_date=date("dS F, Y", $timestamp);

Does anyone have any idea how to format the time from say 19:42:04 to 7:42pm


07-30-2007, 04:26 PM
$str =$row['today_inSQL'].' '.$row['time_inSQL'];
if (($timestamp = strtotime($str)) === false) {
echo "The string ($str) is bogus";
} else {
echo "$str == " . date('dS F, Y / h:i:s', $timestamp);

is this what your looking for or are you looking for a mysql stored time to be converted to that format?
ahh sorry i didnt catch the $row[time_inSQL] :(
hows that?

07-30-2007, 06:44 PM
Its more efficient to do this in mysql if its applicable to your situation..

"SELECT *,DATE_FORMAT(time_inSQL,'%l%i%p') as time_pretty"

see this for all format options.. http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html

07-30-2007, 09:19 PM
Hey thanks, what ive done is put a seperate $, which also works. Thanks for the help.