The short answer is that there is no way to automatically parse arbitrary date formats that will correctly parse all formats out there. In your own example formats, there is just no way to know which numbers are for which date increments.
You can look at the accepted formats of strtotime() and if all your vendors use formats recognized by it, then you are in luck. But if not, the best you can really do is create a lookup table of "vendor" => "format"
and then you can use date_parse_from_format()
edit: *based on comment below, here is a php4 version of an approximation of date_parse_from_format() that should suit your needs*
function date_parse_from_format($format, $date) {
$dMask = array('H'=>'hour','i'=>'minute','s'=>'second','y'=>'year','m'=>'month','d'=>'day');
$format = preg_split('//', $format, -1, PREG_SPLIT_NO_EMPTY);
$date = preg_split('//', $date, -1, PREG_SPLIT_NO_EMPTY);
foreach ($date as $k => $v) {
if ($dMask[$format[$k]]) $dt[$dMask[$format[$k]]] .= $v;
}
return $dt;
}
Basically you need to have a lookup table of vendor => format
where format is a mask of what each character in the date string represents.
NOTE: The masks used for each date/time increments do NOT exactly reflect what is used in php's normal date() string format. It is simplified and meant to mask each individual character of your custom string.
Example:
/*
lookup table for vendors
for EVERY character you want to count as a date/time
increment you must use the following masks:
hour : H
minute : i
second : s
year : y
month : m
day : d
*/
$vendorDateFormats = array(
'vendor1' => 'yyyymmdd',
'vendor2' => 'mmddyyyy',
'vendor3' => 'ddmmyyyy',
'vendor4' => 'yyyy.mm.dd HH:ii:ss'
);
// example 1:
echo "<pre>";
print_r(date_parse_from_format($vendorDateFormats['vendor2'],'03232011'));
// example 2:
echo "<pre>";
print_r(date_parse_from_format($vendorDateFormats['vendor4'],'2011.03.23 12:03:00'));
output:
Array
(
[month] => 03
[day] => 23
[year] => 2011
)
Array
(
[year] => 2011
[month] => 03
[day] => 23
[hour] => 12
[minute] => 03
[second] => 00
)