Source for file date.inc.php
Documentation is available at date.inc.php
* php functions for date handling
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
* @author m2mtech <tech@m2m.at>
* @copyright 2007 m2m server software gmbh
* @license http://www.gnu.org/licenses/gpl.html GNU General Public License Version 2
* @version $Id: date.inc.php 126 2007-08-16 15:59:55Z m2mtech $
* @link http://www.ea-geier.at/
* use of extended date functions of adodb library
require_once(eaADODB_DIR . 'adodb-time.inc.php');
* checks date an returns formated array
* @return boolean/array false/date array
$patternIn = '/^\D*(\d{1,2})\D+(\d{1,2})(?:\D+(\d{1,4}))?\D*$/';
$vars = array(1 => 'day', 2 => 'month', 3 => 'year');
$patternIn = '/^\D*(?:(\d{1,4})\D+)?(\d{1,2})\D+(\d{1,2})\D*$/';
$vars = array(3 => 'day', 2 => 'month', 1 => 'year');
if (!preg_match($patternIn, $date, $match)) return false;
foreach ($vars as $key => $var) {
if (!isset ($match[$key]) || !$match[$key]) $year = date('Y');
else $year = $match[$key];
if ($year < 100) $year += 2000;
if ($month > 12) return false;
if ($day > 31) return false;
if (!checkdate($month, $day, $year)) return false;
$time = adodb_mktime(0, 0, 0, $month, $day, $year);
$return['year'] = adodb_date('Y', $time);
$return['month'] = adodb_date('m', $time);
$return['day'] = adodb_date('d', $time);
$return['date'] = adodb_date($patternOut, $time);
* @return string formated date
function dateFormat(&$data, $format = 'DD.MM.YYYY') {
$vars = array('month', 'day', 'year');
if (isset ($data[$var])) $ $var = $data[$var];
$time = adodb_mktime(0, 0, 0, $month, $day, $year);
return adodb_date($patternOut, $time);
* split combined month-year string
* @param string combined montz & year
* @return array split data
if (!preg_match('/(\d{4})-(\d{2})/', $string, $match)) return false;
$data['year'] = $match[1];
$data['month'] = $match[2];
|