create class function date in php code example
Example 1: php datetime
/**
* Its always best to use a datetime object
*/
$dateTime = new \DateTime();
/**
* You can get the string by using format
*/
$dateTime->format('Y-m-d H:i:s');
Example 2: create date from string php
$element = '15-Feb-2009';
$date = DateTime::createFromFormat('j-M-Y', $element);