HTML Input Type Time Set Value using PHP

input type=time value
html input time format
input type=time 12 hour format w3schools
input type=time 24 hour format javascript
input type=time 24 hour format w3schools
input type=time with am/pm
input type=time set value jquery
what is input system time

I'm trying to display Time in my HTML Input Type Time with AM/PM but it seems that my code is not displaying in the Input Type.

Here's my output for HTML Input Time.

9:00 AM

But my HTML Input Type Time is still

--:-- --

Here's my Code.

<?php
                                    //set up mysql connection
                                    mysql_connect("localhost", "root", "") or die(mysql_error());
                                    //select database
                                    mysql_select_db("db") or die(mysql_error());
                                    //select all records form tblmember table
                                    $query = 'SELECT * FROM newsfeed';
                                    //execute the query using mysql_query
                                    $result = mysql_query($query);
                                   //then using while loop, it will display all the records inside the table
                                    while ($row = mysql_fetch_array($result)) { ?>
      <div class="modal fade" id="myModal<?php echo $row['id'] ?>" role="dialog">
          <div class="modal-dialog">

              <!-- Modal content-->
              <div class="modal-content">
                  <div class="modal-header">
                      <button type="button" class="close" data-dismiss="modal">&times;</button>
                      <h4 class="modal-title">Admin</h4>
                  </div>
                  <div class="modal-body">
                      <form id="updateform" action="admin_update.php" method="post">
                          <fieldset>
                            <!-- image-preview-filename input [CUT FROM HERE]-->
                              <div class="form-group">
                                  <img src="<?php echo $row['image'] ?>" class="img-responsive" />
                              </div>
                              <div class="form-group">
                                  <label>When</label>
                                  <br/>
                                  <input type="time" class="form-control" value="<?php $date = date("h:i A", strtotime($row['time_d'])); echo "$date"; ?>" id="until_t" name="until_t" />
                                  <br/>
                              </div>
                      <div class="modal-footer">
                          <input type="submit" id="btnsave" name="btnsave" class="btn btn-default" value="Save" />
                          <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                      </div>
                  </div>
                  </form>
          </div>
      </div>
          </div>
      </div>

            <?php } ?>

The value of <input type="time" /> need to be in 24 Hr format, without the AM/PM. see http://www.w3.org/TR/html-markup/input.time.html

So try without the A in date(), and H instead of h

<input type="time" class="form-control" value="<?php $date = date("H:i", strtotime($row['time_d'])); echo "$date"; ?>" id="until_t" name="until_t" />

input (type=time) element, will always be in the form name=hh%3Amm , or name=hh%3Amm%3ass if seconds are included (see Using the step attribute). I'm trying to display Time in my HTML Input Type Time with AM/PM but it seems that my code is not displaying in the Input Type. Here's my output for HTML Input Time. 9:00 AM But my HTML Input Type

You have written variable in double quotes. So, instead of this statement in you code.

echo "$date";

Replace it with

echo $date;

HTML DOM Input Time value Property, Web building tutorials with lots of examples of how to use HTML, CSS, JavaScript, SQL, PHP, Python, Bootstrap, Java and XML. Set a time for a time field: The value property sets or returns the value of the value attribute of a time field. Note: The <input type="time"> element does not show as any time field in Firefox. Using a PHP variable in a text input value = statement. I retrieve three pieces of information from the database, one integer, one string, and one date. I echo them out to verify the variables contain the data. When I then use the variables to populate three input boxes on the page, they do not populate correctly.

There is two ways to achieve that the Mysql way and the php way .

Mysql :

SELECT DATE_FORMAT(time_column_name, '%H:%i') FROM table_name // this will return the time the same format as the input of type time sends 

Php :

$formated_time = date("H:i", strtotime($row['time_column_name'])); // this will convert the time to 24 hours also the same the input of type time sends

HTML input type="time", Well organized and easy to understand Web building tutorials with lots of examples of how to use HTML, CSS, JavaScript, SQL, PHP, Python, Bootstrap, Java  The value of the time input is always in 24-hour format: hh:mm, regardless of the input format, which is likely to be selected based on the user's locale (or by the user agent). If the time includes seconds (see Using the step attribute), the format is always hh:mm:ss.

HTML5 input type time setting values not working, See: http://www.w3.org/TR/html-markup/input.time.html into 24-hour one, before passing it to the value attribute of input [type=time]. In this way, one can fetch the time column and display it like this using PHP and mysql. When I use PHP to set the value of a HTML form input element, it works fine provided I don't have any spaces in the data. How to set HTML value attribute (with

HTML, How to set indent the second line of paragraph using CSS ? How to Create How to Upload Image into Database and Display it using PHP ? How to Align Navbar Items <input type=”time”>. The HTML <input type=”time”> is used to specify the entering time control field. input type = "submit" value = "Submit" >. </ form >. The <input type="time"> defines a control for entering a time (no time zone). Tip: Always add the <label> tag for best accessibility practices! The numbers in the table specify the first browser version that fully supports the element.

HTML, How to Upload Image into Database and Display it using PHP ? The DOM Input Time value Property in HTML DOM is used to set or return the value of the value attribute of a Time field. Thie value attribute is input type = "time". id = "gfg​". Input Type Time. The <input type="time"> allows the user to select a time (no time zone). Depending on browser support, a time picker can show up in the input field.

Comments
  • type="time" inputs have to use a valid RFC3339 timev alue. you're not providing that, so you get the default --- stuff. try date('H:i:s') instead. am/pm are not valid in this context.
  • its displaying with 1-12 but when its 13-24 its displaying as AM always AM
  • Need to change h to H -> date("H:i", strtotime($row['time_d']));
  • really thanks man i'm stuck with this input type time for almost 1 hour :D
  • either way works as The most important feature of double-quoted strings is the fact that variable names will be expanded.
  • Provide the value of $row['time_d'] variable.
  • "$foo" and $foo are identical as far as PHP is concerned. this is not the problem.