...

View Full Version : Formatting time?



SMGames
07-30-2007, 03: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

Thanks

rafiki
07-30-2007, 03:26 PM
<?php
$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?

firepages
07-30-2007, 05: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

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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum