- PHP

How to get the Current Date with Time in PHP

Use the date() function.

As a parameter, specify the format you are interested in.

Example 1:

DD.MM.YYYY format with time in 24-hour format and seconds

<?php

echo date("d.m.Y H:i:s") . '<br>';

?>

Example Output: 22.03.2022 14:30:51

Example 2:

MM-DD-YYYY format with time in 12-hour format.

<?php

echo date("m-d-Y g:i:s A") . '<br>';

?>

Example Output: 03-22-2022 2:30:51 PM

Example 3:

MM-DD format with time in 24-hour format.

<?php

echo date("m-d H:i") . '<br>';

?>

Example Output: 03-22 14:30

Example 4:

Month name and day, year, and time in 12-hour format.

<?php

echo date("F j, Y g:i A") . '<br>';

?> 

Example Output: March 22, 2022 2:30 PM