|
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]
|