How to convert a date’s format in PHP?

Spread the love

Sometimes, we want to convert a date’s format in PHP.

In this article, we’ll look at how to convert a date’s format in PHP.

How to convert a date’s format in PHP?

To convert a date’s format in PHP, we call date and strtotime.

For instance, we write

$original_date = "2022-03-21";
$new_date = date("d-m-Y", strtotime($original_date));

to parse the $original_date string into a date with strtotime.

And then we call date with the format string and the parsed date to return a new date string in the DD-MM-YYYY format.

Conclusion

To convert a date’s format in PHP, we call date and strtotime.

Leave a Reply

Your email address will not be published.