def date2str(date, date_format=''):
    """
    Converts a datetime object to a str

    :param date_format: specifies format for date time convcersion. It can be H to show hours,
    M to show hour and minute. Other values will return only the date.
    :type date_format: str
    :param date: date to convert
    :type date: datetime.datetime
    :rtype: str
    """
    if date is None:
        return ''
    if date_format == 'H':
        return '{0:04}{1:02}{2:02}{3:02}'.format(date.year, date.month,
            date.day, date.hour)
    elif date_format == 'M':
        return '{0:04}{1:02}{2:02}{3:02}{4:02}'.format(date.year, date.
            month, date.day, date.hour, date.minute)
    elif date_format == 'S':
        return '{0:04}{1:02}{2:02}{3:02}{4:02}{5:02}'.format(date.year,
            date.month, date.day, date.hour, date.minute, date.second)
    else:
        return '{0:04}{1:02}{2:02}'.format(date.year, date.month, date.day)
