I am working in php in which i am using mysql.
This is my function which is returning result in json format.
function getTiming($placeId) {
$sql = "SELECT * from place_timing where placeId='$placeId'";
$result = mysql_query($sql) or die ("Query error: " . mysql_error());
$records = array();
if (mysql_num_rows($result)==0)
{
echo '['.json_encode(array('placeId' => 0)).']';
//this is for null result
}
else
{
while($row = mysql_fetch_assoc($result))
{
$records[] = $row;
}
echo json_encode($records); //this concerts in json
}
}
output of this function is like this:-
[{"placeId":"31","sun_open_time":"00:00:00","sun_close_time":"00:00:00","mon_open_time":"00:00:00","mon_close_time":"23:00:00","tue_open_time":"00:00:00","tue_close_time":"00:00:00"}]
But I want to show only hour:minutes. means I don’t want to show seconds.
please suggest me how can I change my above function so I can show only hour:minutes.
Thank you in advance.
There are many ways to do it, the “cleanest” would be to specify the columns in the SELECT clause and pass the dates with DATE_FORMAT() like this:
DATE_FORMAT(sun_open_time, '%H:%i').