How to fix strtotime() doesn’t work with dd/mm/YYYY format with PHP?

Spread the love

Sometimes, we want to fix strtotime() doesn’t work with dd/mm/YYYY format with PHP.

In this article. we’ll look at how to fix strtotime() doesn’t work with dd/mm/YYYY format with PHP.

How to fix strtotime() doesn’t work with dd/mm/YYYY format with PHP?

To fix strtotime() doesn’t work with dd/mm/YYYY format with PHP, we replace the slashes with dashes.

For instance, we write

$date = "25/05/2020";
$date = str_replace("/", "-", $date);
echo date("Y-m-d", strtotime($date));

to call str_replace to replace the slashes with dashes in the $date string.

Then we call date with 'Y-m-d' and strtotime($date) to create a date with the $date string.

Conclusion

To fix strtotime() doesn’t work with dd/mm/YYYY format with PHP, we replace the slashes with dashes.

Leave a Reply

Your email address will not be published.