sábado, 15 de enero de 2022

convert date object to string

 $date = new DateTime('2000-01-01');

$result = $date->format('Y-m-d H:i:s');

If format fails for some reason, it will return FALSE. In some applications, it might make sense to handle the failing case:

if ($result) {
  echo $result;
} else { // format failed
  echo "Unknown Time";
}


............Other example-----------------
printing  a date time object called   $record->dateSent
 $rdate = $record->dateSent->format('Y-m-d H:i:s');