Reply to Re: Date recognition

Your name:

Reply:


Posted by iuz on 06/04/05 19:26

Mikki wrote:

> What is the best way do recognize a date from a string and convert it
> to unix timestamp?
>
> Strtotime() function is working only with US dates (MM/DD/YYYY), I need
> something for European dates (DD/MM/YYYY).
>
> thankssss

try to examine this (regex + checkdate + mktime|strtotime)..
<?php

$dateList = array(
'12-11-2005',
'5/04/2005',
' 12-9/2005',
'16 13 2005 ',
' 28-1-2005 ',
'12/10k2005',
'132-13-2005');

while (list(, $date) = each($dateList)) {

if (!preg_match('/^ *([0-9]{1,2})[\-\/ ]([0-9]{1,2})[\-\/ ]([0-9]{1,4})
*$/', $date, $matches)) {
echo "date format not valid ($date)<br />";
continue;
}

if (!checkdate($matches[2], $matches[1], $matches[3])) {
echo "date values not valid ($date)<br />";
continue;
}

echo "date valid '$date' = '" . date('d-m-Y', mktime (0, 0, 0,
$matches[2], $matches[1], $matches[3])) . "'<br />";

}

?>

--
www.iuz-lab.info

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация