In this article, you will learn how to create a new DateTime object in PHP. The date_create() function creates a new DateTime Object that is very useful and important for PHP developers because it is required in many functions and also in database columns.
What is the syntax of the date_create() function in PHP?
date_create(time, timezone)
Parameters | Details |
---|---|
time | Specify the Date/Time string – Required – Null means current Date/Time |
timezone | Specify the Timezone – Optional – Null means current Timezone |
Examples of the date_create() function
Example 1. In the following example. we create and return a new DateTime object and then format it according to the specific format.
<?php
$d=date_create("1998-01-04");
echo date_format($d,"Y/m/d");
?>