0

Hello everybody, Once I click Submit button I want to display hour with seconds in HTML form using PHP. Can anyone tell how to do it?

Amit Agarwal
  • 10,910
  • 1
  • 32
  • 43
php16
  • 1
  • 4
  • if you want to just display hours with seconds after submit you can do like this. if($_REQUEST) { echo date('d-m-Y H:i'); } – Ashish Patel Nov 26 '16 at 08:07
  • Possible duplicate of [How to get the current date and time in PHP?](http://stackoverflow.com/questions/470617/how-to-get-the-current-date-and-time-in-php) – Mike F Nov 26 '16 at 10:45

2 Answers2

1
 <?php
  $datetime = '';
  if(isset($_REQUEST['submit']))
   {

    $datetime = date("h:i:sa");
  }
 ?>

 <form method="POST">
 <textarea><?php echo $datetime; ?></textarea>
 <input type="submit" name="submit" value="Show Time" />

 </form>
?>
0

Just as example you can try the following code and for more details about time in

  <?php
  if($_REQUEST['submit'])
  {
   echo "Today is " . date("Y/m/d") . "<br>"; // Today is 2016/11/26
   echo  "Time is" . date("h:i:sa"); // prints the time
  ?>
  <!-- To display time in textarea you can use the following code -->
 <textarea><?php echo date("h:i:sa"); ?></textarea>
<?php } ?>

<form action="" method="get">
  <textarea><?php echo date("h:i:sa"); ?></textarea>
  <input type="submit" name="submit" value="Show Time" />

</form>

Please note that you should save the file with .php extension

Deep Kakkar
  • 5,831
  • 4
  • 39
  • 75