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.

Code PHP:
$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?