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?
Asked
Active
Viewed 1,317 times
0
-
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 Answers
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>
?>

Rahool Dhokiya
- 135
- 6
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
-
I just updated my code so that you can display time in textarea form as well after form submitted also in the textarea form. :) – Deep Kakkar Nov 26 '16 at 09:08
-