xxxxxxxxxx
Date to string
$date = "2021/03/13";
$newdate= date('d M, Y', strtotime($date));
echo $newdate;
xxxxxxxxxx
<?php
$date = new DateTime('2000-01-01');
echo $date->format('Y-m-d H:i:s');
?>
xxxxxxxxxx
$element = '15-Feb-2009';
$date = DateTime::createFromFormat('j-M-Y', $element);
xxxxxxxxxx
$date_string_prepared = date_create("2020-08-07");
$date_string = $date_string_prepared->format("d M Y");
// result 07 Jul 2020
xxxxxxxxxx
phpCopy$theDate = new DateTime('2020-03-08');
echo $stringDate = $theDate->format('Y-m-d H:i:s');
//output: 2020-03-08 00:00:00
xxxxxxxxxx
$date = new DateTime(); // Create a DateTime object with the current date and time
$dateString = $date->format('Y-m-d H:i:s'); // Convert the date to a string format ("Y-m-d H:i:s" is just an example format)
echo $dateString; // Output the converted date string
xxxxxxxxxx
phpCopy$date = date_create_from_format('d M, Y', '08 Mar, 2020');
echo $newFormat = date_format($date,"Y/m/d H:i:s");
//output: 2020/03/08 00:00:00
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
xxxxxxxxxx
phpCopy$dateFormat = new DateTime(); // this will return current date
echo $stringDate = $date->format(DATE_ATOM);
//output: 2020-03-08T12:54:56+01:00
xxxxxxxxxx
phpCopydefine ('DATE_ATOM', "Y-m-d\TH:i:sP");
define ('DATE_COOKIE', "l, d-M-y H:i:s T");
define ('DATE_ISO8601', "Y-m-d\TH:i:sO");
define ('DATE_RFC822', "D, d M y H:i:s O");
define ('DATE_RFC850', "l, d-M-y H:i:s T");
define ('DATE_RFC1036', "D, d M y H:i:s O");
define ('DATE_RFC1123', "D, d M Y H:i:s O");
define ('DATE_RFC2822', "D, d M Y H:i:s O");
define ('DATE_RFC3339', "Y-m-d\TH:i:sP");
define ('DATE_RSS', "D, d M Y H:i:s O");
define ('DATE_W3C', "Y-m-d\TH:i:sP");