xxxxxxxxxx
$dateString = '2022-12-31';
$dateTime = new DateTime($dateString);
$formattedDate = $dateTime->format('Y-m-d'); // Change the format code as per your needs
echo $formattedDate;
xxxxxxxxxx
To convert the date-time format PHP provides strtotime() and date() function. We change the date format from one format to another.
Change YYYY-MM-DD to DD-MM-YYYY
<? php.
$currDate = "2020-04-18";
$changeDate = date("d-m-Y", strtotime($currDate));
echo "Changed date format is: ". $changeDate. " (MM-DD-YYYY)";
?>
xxxxxxxxxx
$originalDate = "2010-03-21";
$newDate = date("d-m-Y", strtotime($originalDate));
xxxxxxxxxx
$currDate = "2020-08-25";
$changeDate = date("d-m-Y", strtotime($currDate));
echo $changedDate;
xxxxxxxxxx
<?php
#https://moneyconvert.net/
$source = '2012-07-31';
$date = new DateTime($source);
echo $date->format('d.m.Y'); // 31.07.2012
echo $date->format('d-m-Y'); // 31-07-2012
?>
xxxxxxxxxx
function correctDateTime($dateTime)
{
# integer digits for Julian date
$julDate = floor($dateTime);
# The fractional digits for Julian Time
$julTime = $dateTime - $julDate;
# Converts to Timestamp
$timeStamp = ($julDate > 0) ? ($julDate - 25569) * 86400 + $julTime * 86400 : $julTime * 86400;
# php date function to convert local time
return [
"Date-Time"=>date("Y-m-d H:i:s", $timeStamp),
"Date"=>date("Y-m-d", $timeStamp),
"Time"=>date("H:i:s", $timeStamp)
];
}
$formattedValue = correctDateTime("44225.403368056");
echo $formattedValue["Date-Time"] . "\n"; // 2021-01-29 09:40:51
echo $formattedValue["Date"] . "\n"; // 2021-01-29
echo $formattedValue["Time"] . "\n"; // 09:40:51