import re
from datetime import datetime


def to_datetime(date):
    """
    Converts string to a date type.
    >>> to_datetime('21st May 2012')
    >>> datetime(2012, 5, 21, 0, 0)
    """
    date = re.sub(r'\d+(st|nd|rd|th)', lambda m: m.group()[:-2].zfill(2), date)
    return datetime.strptime(date, '%d %b %Y')