peter Ojeda
asked on
echo time from sql to input type="time"
Hi experts, I am creating an update area of my form where I echo the results of a record to a table, then on submit it updates that record. The issue is echoing "time" fields. If I echo a time from my sqlserver to a text input, I can see the time but when I submit it it submits as a text and is 0, but when I echo to a "time" field it does not echo the time from the sqlserver,
<input type="time" name="JOB_STOP_TIME" size="20" value="<?php echo $result["JOB_STOP_TIME"]->format("h/i/a");?>">
ASKER
Hi Ray yes I am storing the entire date-time value in the database,I was just testing to see what will work with updating the time so I was only echoing the time. I am able to echo from the database to a text input correctly, but not to a time input which is what I am attempting to do.
OK, I think I understand. Please show us one of the date/time values from your database. I will try to show you how to get this into a time format.
You should know that the 'date' and 'time' input types are not supported in Firefox yet.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you Ray this is exactly what I was attempting to do. I know this is an easy question but how would I set $my_DB_time to the column name? I've tried $result["JOB_STOP_TIME"] and a number of other ways but am not sure what I am doing wrong.
ASKER
Sorry ofcourse after spending a hour attempting I ask a question and then an able to solve the answer.
Thanks for the points. If you still have questions about getting the DB values into your PHP script, please post another question in the PHP and MySQL Server zones. I'll se anything in the PHP Zone and will be glad to help!
<?php echo $result["JOB_STOP_TIME"]->
My guess is that's not the case, and instead the SQL column is really a data type of DATETIME. If that is so, the DATETIME value will be returned as a PHP string value. You can use the PHP functions strtotime() and date() if you need special formatting for display in the browser. In my tests, the standard display in an input control of type=time were pretty sensible.
These articles show how to handle date/time values in PHP and MySQL. You might want to bookmark them.
Procedural
https://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL-Procedural-Version.html
Object-oriented
https://www.experts-exchange.com/articles/20920/Handling-Time-and-Date-in-PHP-and-MySQL-OOP-Version.html
This script seems to work correctly. If you're storing a time value in the database, you probably want to store the entire date/time value and not just the hour of the day.
https://iconoun.com/demo/temp_peter_ojeda.php
Open in new window