<?php
echo “<pre>”;
$interval = DateInterval::createFromDateString(‘1 month’);
print_r($interval);
?>
Output
DateInterval Object
(
[y] => 0
[m] => 1
[d] => 0
[h] => 0
[i] => 0
[s] => 0
[invert] => 0
[days] => 0
)
<?php
echo “<pre>”;
$interval = DateInterval::createFromDateString(‘1 month’);
print_r($interval);
?>
Output
DateInterval Object
(
[y] => 0
[m] => 1
[d] => 0
[h] => 0
[i] => 0
[s] => 0
[invert] => 0
[days] => 0
)
<?php
echo “<pre>”;
$interval = DateInterval::createFromDateString(‘1 month’);
print_r($interval);
?>
Output
DateInterval Object
(
[y] => 0
[m] => 1
[d] => 0
[h] => 0
[i] => 0
[s] => 0
[invert] => 0
[days] => 0
)
<?php
echo “<pre>”;
try {
$date = new DateTime(‘phpcodez’);
} catch (Exception $e) {
print_r(DateTime::getLastErrors());
}
?>
Output
Array
(
[warning_count] => 1
[warnings] => Array
(
[6] => Double timezone specification
)
[error_count] => 1
[errors] => Array
(
[0] => The timezone could not be found in the database
)
)
<?php
echo “<pre>”;
$date = date_create(‘phpcodez’);
print_r(date_get_last_errors());
?>
Output
Array
(
[warning_count] => 1
[warnings] => Array
(
[6] => Double timezone specification
)
[error_count] => 1
[errors] => Array
(
[0] => The timezone could not be found in the database
)
)
<?php
$date = new DateTime(‘2007-05-17’);
echo $date->format(‘Y-m-d H:i:s’);
?>
Output
2007-05-17 00:00:00
It Returns date formatted according to given format and is an alias of DateTime::format()
Example
<?php
$date = date_create(‘2007-05-17’);
echo date_format($date, ‘Y-m-d H:i:s’);
?>
Output
2007-05-17 00:00:00
CSScaffold is a CSS framework written in PHP. it uses PHP to extend CSS. The syntax looks and feels like CSS, except that you have some powerful abilities.
The best part is that all of this is done transparently. You can drop Scaffold into your site and you’ll instantly have access to all of its functionality. Scaffold requires a web server with PHP 5+ and Mod_rewrite should enabled if you want it work automatically .
<?php $items = wp_get_nav_menu_items( $menu, $args ); ?>
Here $menu can menu name,id or slug
$args can be
<?php $args = array(
‘orderby’ => ‘menu_order’,
‘post_status’ => ‘publish’ );
?>
<?php
$menuId=51;
foreach(wp_get_nav_menu_items($menuId) as $menu) {
echo $menu->title.”<br />”;
}
?>
<?php
$datetime1 = new DateTime(‘2009-5-17’);
$datetime2 = new DateTime(‘2012-5-17’);
$interval = $datetime1->diff($datetime2);
echo $interval->format(‘%R%a days’);
?>
Output
+1096 days