In this article, you will learn how to create a new date in a specific format. The PHP date_create_from_format() function creates a new date in the specified format.
What is the syntax of the date_create_from_format() in PHP?
date_create_from_format(format, time, timezone)
Parameter | Description |
---|---|
format | Specify the format to use – Required |
time | Date/time string – Required – Null means current date/time |
timezone | The timezone of time – Optional – Null means current Timezone |
The characters which can be used in the format parameters are as follows.
Examples of the date_create_from_format() function
Example 1. In the following example, we specify the format to create a new date in this format.
<?php
$date=date_create_from_format("j-M-Y","04-Jan-1998");
?>