Convert string to date by passing pattern?

Having trouble researching this one or coming up with my own solution. I need to be able to pass a date/time pattern that will then used to convert a string to DateTime.


$string = '20130408164312'; // yyyymmddhhmmss
$string2 = '2013-04-08 16:43:12'

I should be able to pass both of those strings to a function, along with some sort of pattern string and be able to return a DateTime object. I’m trying to make this completely versatile. Ideas/functions you’ve already come across?

Doesn’t PHP already support this? http://us3.php.net/manual/en/datetime.createfromformat.php

Ya, I was just coming back to paste that myself… My googling skills weren’t on par today I suppose. Thanks.