PhpRiot
Become Zend Certified

Prepare for the ZCE exam using our quizzes (web or iPad/iPhone). More info...


When you're ready get 7.5% off your exam voucher using voucher CJQNOV23 at the Zend Store

Create Dates from an Array

Dates can also be created by the usage of an array. This is a simple and easy way. The used array keys are:

  • day: day of the date as number

  • month: month of the date as number

  • year: full year of the date

  • hour: hour of the date

  • minute: minute of the date

  • second: second of the date

Example 177. Date Creation by Array

Normally you will give a complete date array for creation of a new date instance. But when you do not give all values, the not given array values are zeroed. This means that if f.e. no hour is given the hour 0 is used.

<?php
$datearray 
= array('year' => 2006,
                   
'month' => 4,
                   
'day' => 18,
                   
'hour' => 12,
                   
'minute' => 3,
                   
'second' => 10);
$date = new Zend_Date($datearray);
<?php
$datearray 
= array('year' => 2006'month' => 4'day' => 18);
$date = new Zend_Date($datearray);

Zend Framework