xxxxxxxxxx
$element = '15-Feb-2009';
$date = DateTime::createFromFormat('j-M-Y', $element);
xxxxxxxxxx
Date to string
$date = "2021/03/13";
$newdate= date('d M, Y', strtotime($date));
echo $newdate;
xxxxxxxxxx
$date_string_prepared = date_create("2020-08-07");
$date_string = $date_string_prepared->format("d M Y");
// result 07 Jul 2020
Simple way to show to and from date using php
xxxxxxxxxx
$dateto = new DateTime('now');
$datefrom = new DateTime( date('Y-m-d', strtotime("-1 year", time())) );
xxxxxxxxxx
$date = new DateTime(); // current date and time
$dateString = $date->format('Y-m-d H:i:s'); // convert to string format
echo $dateString; // output the converted date string