Home >>PHP Date Time Functions >PHP date_create() Function

PHP date_create() Function

PHP date_create() Function

The date_create() function is used to returns a new DateTime object. It accepts two optional parameters $time and $timezone.

Syntax:

 date_create($time, $timezone);

Parameter Values

Parameter Description
time This is an optional 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() function in PHP:

<html>
<body>

<?php

$date=date_create();
echo date_format($date,"d-M-Y");

?>

</body>
</html>
Output:
31-Jan-2020

Here is another example of date_create() function in PHP:

<html>
<body>

<?php

$date=date_create("14-02-2020");
echo date_format($date,"d-M-Y (D)");

?>

</body>
</html>
Output:
14-Feb-2020 (Fri)

No Sidebar ads