It returns details about given date formatted according to the specified format.
Example
<?php
echo “<pre>”;
$date = “20.4.2008”;
print_r(date_parse_from_format(“j.n.Y H:iP”, $date));
?>
Output
Array
(
[year] => 2008
[month] => 4
[day] => 20
[hour] =>
[minute] =>
[second] =>
[fraction] =>
[warning_count] => 0
[warnings] => Array
(
)
[error_count] => 1
[errors] => Array
(
[9] => Data missing
)
[is_localtime] =>
)
It returns the timezone offset .
Example
<?php
$time = new DateTime(‘2008-05-17’, new DateTimeZone(‘America/New_York’));
echo $time->getOffset() . “n”;
?>
Output
-14400
Example
<?php
$time = date_create(‘2012-05-17’, timezone_open(‘America/New_York’));
echo date_offset_get($time) . “n”;
?>
Output
-14400
It returns information about the operating system PHP is running on
Example
<?php
echo php_uname();
?>
Ouput
Linux phpcodez-System-Product-Name 2.6.35-22-generic #35-Ubuntu SMP Sat Oct 16 20:36:48 UTC 2010 i686
It returns canonicalized absolute pathname
Example
<?php
chdir(‘/usr/local/’);
echo realpath(‘./../../var/www/’);
?>
Ouput
/var/www
It alters the timestamp
Example
<?php
$date = new DateTime(‘2006-05-17’);
$date->modify(‘+2 day’);
echo $date->format(‘Y-m-d’);
?>
Output
2006-05-19
Example
<?php
$date = date_create(‘2007-05-17’);
date_modify($date, ‘+2 day’);
echo date_format($date, ‘Y-m-d’);
?>
Output
2007-05-19
It sets the ISO date .
Example
<?php
$date = new DateTime();
$date->setISODate(2007, 7);
echo $date->format(‘Y-m-d’) ;
?>
Output
2007-02-12
It sets the ISO date and is an alias of
DateTime::setISODate()
Example
<?php
$date1 = date_create();
date_isodate_set($date1, 2007, 2);
echo date_format($date1, ‘Y-m-d’);
?>
Output
2007-01-08
It formats the interval
Example
<?php
$interval = new DateInterval(‘P12Y14DT16H18M’);
echo $interval->format(‘%d days’);
?>
Output
14 days
Zend | Magento Certified PHP | eCommerce Architect