PHP date_create() Function

In this chapter you will learn:

  1. Definition for PHP date_create() Function
  2. Syntax for PHP date_create() Function
  3. Parameter for PHP date_create() Function
  4. Return value for PHP date_create() Function
  5. Example - Return a new DateTime object, and then format the date
  6. Example - Return a new DateTime object (with a given timezone), and then format the date and time

Definition

The date_create() function returns a new DateTime object.

Syntax

PHP date_create() Function has the following syntax.

date_create(time,timezone);

Parameter

PHP date_create() Function has the following parameters.

ParameterIs RequiredDescription
timeOptional.A date/time string. NULL indicates the current time.
timezoneOptional.Timezone of time. Default is the current timezone.

Return

PHP date_create() Function returns a new DateTime object on success. FALSE on failure.

Example 1

Return a new DateTime object, and then format the date:


<?php
$date=date_create("2013-01-15");
echo date_format($date,"Y/m/d");
?>

The code above generates the following result.

Example 2

Return a new DateTime object (with a given timezone), and then format the date and time:


<?php
$date=date_create("2013-02-15 21:40:00",timezone_open("Europe/Oslo"));
echo date_format($date,"Y/m/d H:iP");
?>

The code above generates the following result.

Next chapter...

What you will learn in the next chapter:

  1. Definition for PHP date_create_from_format() Function
  2. Syntax for PHP date_create_from_format() Function
  3. Parameter for PHP date_create_from_format() Function
  4. Return for PHP date_create_from_format() Function
  5. Example - Return a new DateTime object formatted according to the specified format
Home » PHP Tutorial » PHP Date Functions
PHP checkdate() Function
PHP date() Function
PHP date_add() Function
PHP date_create() Function
PHP date_create_from_format() Function
PHP date_date_set() Function
PHP date_default_timezone_get() Function
PHP date_default_timezone_set() Function
PHP date_diff() Function
PHP date_format() Function
PHP date_get_last_errors() Function
PHP date_interval_format() Function
PHP date_isodate_set() Function
PHP date_modify() Function
PHP date_offset_get() Function
PHP date_parse() Function
PHP date_parse_from_format() Function
PHP date_sub() Function
PHP date_sun_info() Function
PHP date_sunrise() Function
PHP date_sunset() Function
PHP date_time_set() Function
PHP date_timestamp_get() Function
PHP date_timestamp_set() Function
PHP date_timezone_get() Function
PHP date_timezone_set() Function
PHP getdate() Function
PHP gettimeofday() Function
PHP gmdate() Function
PHP gmmktime() Function
PHP gmstrftime() Function
PHP idate() Function
PHP localtime() Function
PHP microtime() Function
PHP mktime() Function
PHP strftime() Function
PHP strptime() Function
PHP strtotime() Function
PHP time() Function
PHP Timezones Constant
PHP timezone_abbreviations_list() Function
PHP timezone_identifiers_list() Function
PHP timezone_location_get() Function
PHP timezone_name_from_abbr() Function
PHP timezone_name_get() Function
PHP timezone_offset_get() Function
PHP timezone_open() Function
PHP timezone_version_get() Function