It depends on what you need to do but the below should put you on the right path.
PHP Code:
$matches = array();
$str = 'DateCreated <= \'2009-05-01\' AND DateUpdated';
$exp = preg_match('/^DateCreated\s\<=\s\'([0-9]{4})-([0-1]?[0-9])-([0-1]?[0-9])\'\sAND\sDateUpdated$/',$str,$matches);
echo '<pre>',print_r($matches),'</pre>';
The below will give you just the date string which you could then use explode on to extract the year,month and day.
PHP Code:
$str = 'DateCreated <= \'2009-05-01\' AND DateUpdated';
$exp = preg_replace('/^DateCreated\s\<=\s\'([0-9]{4})-([0-1]?[0-9])-([0-1]?[0-9])\'\sAND\sDateUpdated$/','$1-$2-$3',$str);
echo '<p>',$exp,'</p>';
Here is the entire thing resulting in an array for the year,day,month.
PHP Code:
$str = 'DateCreated <= \'2009-05-01\' AND DateUpdated';
$date = explode('-',preg_replace('/^DateCreated\s\<=\s\'([0-9]{4})-([0-1]?[0-9])-([0-1]?[0-9])\'\sAND\sDateUpdated$/','$1-$2-$3',$str));
echo '<pre>',print_r($date),'</pre>';
You could also do something a little fancier which maps the associative keys.
PHP Code:
$str = 'DateCreated <= \'2009-05-01\' AND DateUpdated';
$date = array_combine(array('year','month','day'),explode('-',preg_replace('/^DateCreated\s\<=\s\'([0-9]{4})-([0-1]?[0-9])-([0-1]?[0-9])\'\sAND\sDateUpdated$/','$1-$2-$3',$str)));
echo '<pre>',print_r($date),'</pre>';
Bookmarks