from datetime import datetime
import time


def to_epoch(date_time):
    """
    Convert datetime to epoch

    :param date_time: datetime
    :return: epoch
    """
    pattern = '%Y-%m-%d %H:%M:%S'
    earliest = datetime(1970, 1, 1, 0, 0, 0, 0)

    if date_time is None:
        date_time = str(datetime.now()).split(" ")[0]

    if time.strptime(str(date_time), pattern).tm_year < earliest.year:
        date_time = str(earliest).split(" ")[0]

    epoch = int(time.mktime(time.strptime(str(date_time), pattern)))
    return epoch