How to convert one date format into another in PHP?

Spread the love

Sometimes, we want to convert one date format into another in PHP.

In this article, we’ll look at how to convert one date format into another in PHP.

How to convert one date format into another in PHP?

To convert one date format into another in PHP, we can use the format method.

For instance, we write

$now = new DateTime();
$timestring = $now->format('Y-m-d h:i:s');

to call format in the $now datetime with the format string.

Y is the 4 digit year, m is the 2 digit month, d is the 12 digit day of the month.

h is the hour, i is the minute, and s is the seconds.

Conclusion

To convert one date format into another in PHP, we can use the format method.

Leave a Reply

Your email address will not be published. Required fields are marked *