php - MYSQL TIME without seconds
Get the solution ↓↓↓In PHPmyAdmin I stored times with TIME function. They are displayed as hh:mm:ss. With PHP I want to remove the seconds and use following script:
$startTime = $row["open"];
$print_time = date("H:i", strtotime($startTime));
It returnes "01:00", the seconds are removed, but the time should display "11:50" or "14:17", per example.
Answer
Solution:
date("H:i", strtotime($startTime));
returns'01:00'
whenstrtotime($startTime)
returns a value 0-60.
strtotime($startTime);
returnsfalse
(0) when$startTime
doesn't match a valid time format as described at https://www.php.net/manual/en/datetime.formats.time.php.
$startTime = '06:00:00';
$print_time = date("H:i", strtotime($startTime));
var_dump($print_time);
outputsstring(5) "06:00"
$startTime = 'invalidformat'; // E.g. $startTime = false;
$print_time = date("H:i", strtotime($startTime)); // strtotime($startTime) returns false
var_dump($print_time);
outputsstring(5) "01:00"
Please double check the value of$startTime
.
E.g.var_dump($startTime);
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: filter_sanitize_string
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.