- PHP

How to get Current Hour in PHP

Use date() function.

Example:

<?php 
  echo date("H") . '<br>'; // 13
  echo date("h") . '<br>'; // 01
  echo date("h a") . '<br>'; // 01 pm
  echo date("h A") . '<br>'; // 01 PM
?>

We can also combine these values with other date() parameters.

Here’s an example of how to display current hour, minute and second:

<?php 
  echo date("H:i:s");
?>

Example output (depending on the current hour on the server): 13:48:09