Get current time with php


This code returns the current time, but I need it a minute ago.

  <input type="text" value="<?php echo date("h:i:s A");?>">

Can you do that if the current time is 2pm; the input show me the 13:59?

asked by Johan Solano Contreras 30.08.2018 в 08:41

2 answers


The second (optional) argument of the date() function is a timestamp . So you can put the format as the first argument and as a second argument strtotime("-1 minute") :

  <input type="text" value="<?php echo date("h:i:s A", strtotime("- 1 minute"));?>">
answered by 30.08.2018 / 08:55

You can use strtotime for it

$nuevafecha = strtotime ( '-1 minute' , strtotime ( date("h:i:s A")) ) ;

<input type="text" value="<?php echo $nuevafecha ;?>">

Calculated in the input directly

<input type="text" value="<?php echo strtotime ( '-1 minute' , strtotime ( date("h:i:s A")) );?>">
answered by 30.08.2018 в 08:49