1
I intend to convert the time I receive that comes from an input time (01:00) to the "his" format I want the result to be 010000. I used this code, it worked but notice error.
$hour=date("his",$txthourstart);
How can I convert to this format?
1
I intend to convert the time I receive that comes from an input time (01:00) to the "his" format I want the result to be 010000. I used this code, it worked but notice error.
$hour=date("his",$txthourstart);
How can I convert to this format?
1
Prefer to use the methods and classes provided by PHP to use the interpretation of temporal data. There are two main solutions:
Object Oriented (>= PHP 5.2)
$hourStart = DateTime::createFromFormat("H:i", $txthourstart);
$hour = $hourStart->format('His');
Procedural
$hour = date("His", strtotime($txthourstart));
Browser other questions tagged php
You are not signed in. Login or sign up in order to post.
You used strtotime() to convert the value?
– Guilherme Portela
No, you have to convert?
– akm
It is recommended because direct string assignment will cause errors in data interpretation.
– Guilherme Portela
I used $hora=strtotime($txthourstart); but if I have 23:00, put it to 110000. I wanted the result to be 230000.
– akm
Then use "His". The "H" character represents the format in 24 hours, while the "h" represents it in 12.
– Guilherme Portela