I try to do it this way but the date change does not work for me, if someone can help me
$originalDate = "19/10/2022";
$timestamp = strtotime($originalDate);
$newDate = date("Y-m-d", $timestamp );
echo $newDate;
I try to do it this way but the date change does not work for me, if someone can help me
$originalDate = "19/10/2022";
$timestamp = strtotime($originalDate);
$newDate = date("Y-m-d", $timestamp );
echo $newDate;
You would have to initialize the variable
$timestamp
as an object typeDateTime()
and then change the date format to it like this:Your final code would look like this:
If you want to use dates that contain
/
, you would have to replace the/
with-
since DateTime() only accepts dates with-
. For this case, you would usestr_replace
:And your code would look like this: