Home >>PHP Date Time Functions >PHP date_create_from_format() Function
PHP date_create_from_format() function is used to format a given time string according to a specified format. It accepts three parameters $format, $time and $timezone. It returns new DateTime as output in success or false on failure.
Syntax:
date_create_from_format( $format, $time, $timezone );
Parameter | Description |
---|---|
format | This is a required parameter. This parameter defines the format to use. |
time | This is a required parameter. This parameter defines a date/time string. |
timezone | This is an optional parameter. This parameter defines the timezone of time. |
Here is an example of date_create_from_format() function in PHP:
<html> <body> <?php $date=date_create_from_format("j-M-Y","1-July-2020"); echo date_format($date,"d/m/Y"); ?> </body> </html>
Here is another example of date_create_from_format() function in PHP:
<html> <body> <?php $date=date_create_from_format("D-M-Y","SUN-June-2020"); echo date_format($date,"d-m-Y"); ?> </body> </html>