<!DOCTYPE html>
<html>
<body>
<?php
$date=date_create_from_format("l d F Y, H:i:s A","Wednesday 15 January 2025, 14:11:05
PM");
echo date_format($date,"Y-m-d");
?>
This is returning 2025-01-22 i'm not sure what am missing.
<!DOCTYPE html>
<html>
<body>
<?php
$date=date_create_from_format("l d F Y, H:i:s A","Wednesday 15 January 2025, 14:11:05
PM");
echo date_format($date,"Y-m-d");
?>
This is returning 2025-01-22 i'm not sure what am missing.
The A flag is for AM/PM, which is completely unnecessary for 24- hour formats, which upper- case H stands for.
Either use 24- hour format, like this:
$date = date_create_from_format(
"l d F Y, H:i:s", // Upper- case H, but no A at the end.
"Wednesday 15 January 2025, 14:11:05" // Skip the "PM"
);
Or 12- hour format, like this:
$date = date_create_from_format(
"l d F Y, h:i:s A", // Lower- case h, for 12 hour format.
"Wednesday 15 January 2025, 2:11:05 PM"
);
<?php
setlocale(LC_TIME, 'en_US.UTF-8'); // Ensure correct language format
date_default_timezone_set('Asia/Kolkata'); // Set your timezone or you
can remove this as well using here because of server time mismatch
$dateString = trim("Wednesday 15 January 2025, 02:11:05 PM");
$date = date_create_from_format("l d F Y, h:i:s A", $dateString);
echo "Formatted Date: " . date_format($date, "Y-m-d");
echo "<br>";
echo "Time: " . date_format($date, "h:i:s A");
echo "<br>";
echo "Day: " . date_format($date, "l");
echo "<br>";
echo "Date & Time : " . date_format($date, "Y-m-d h:i:s A");
echo "<br>";
echo "Date & Time & Day : " . date_format($date, "Y-m-d h:i:s A l");
?>