Skip to content
PHP Logo

What function can be used to format date and time in PHP?

To format date and time in PHP, you can use the date() function. This function allows you to specify a format string that defines how the date and time should be displayed. You can include various placeholders in the format string to represent different parts of the date and time, such as day, month, year, hour, minute, and second.

php
// Example of formatting current date and time
$date = date('Y-m-d H:i:s');
echo $date;