Create new DateTime object from string(2014-02-15) in PHP

Description

The following code shows how to create new DateTime object from string(2014-02-15).

Example


/*from  w  w w.j ava 2s .  co  m*/
<?php
echo 'Current time: ' . date('Y-m-d H:i:s') . "\n";

$format = 'Y-m-d';
$date = DateTime::createFromFormat($format, '2014-02-15');
echo "Format: $format; " . $date->format('Y-m-d H:i:s') . "\n";

?>

The code above generates the following result.





















Home »
  PHP Tutorial »
    Data Types »




Array
Array Associative
Array Util
ArrayObject
Data Types
Date
Date Format
DateTime
Number
String
String Escape
String Filter
String HTML
String Type
Timezone