9951 explained code solutions for 126 technologies


php-symfonyHow to get the current date in PHP Symfony?


The current date can be obtained in PHP Symfony using the DateTime class.

Example code

$date = new \DateTime();
echo $date->format('Y-m-d H:i:s');

Output example

2020-09-17 11:45:00

Code explanation

  • $date = new \DateTime();: creates a new DateTime object
  • echo $date->format('Y-m-d H:i:s');: formats the date object to the desired format

Helpful links

Edit this code on GitHub