def get_t_factor(t1, t2):
    """Time difference between two datetimes, expressed as decimal year 
    """
    t_factor = None
    if t1 is not None and t2 is not None and t1 != t2:  
        dt = t2 - t1
        year = timedelta(days=365.25)
        t_factor = abs(dt.total_seconds() / year.total_seconds()) 
    return t_factor
Time difference between two datetimes, expressed as decimal year