import re


def add_datepart(df, fieldname):
    """
    Adds date related features to dataframe df inplace
    df: dataframe
    fieldname: name of the date field in df
    """
    new_df = df.copy()
    field = df[fieldname]
    target_prefix = re.sub('[Dd]atetime$', '', fieldname)
    
    date_features = (
         'hour',
         'minute',
         'Year', 
         'Month', 
         'Week', 
         'Day', 
         'Dayofweek', 
         'Dayofyear', 
    )
    
    for name in date_features:
        new_df[target_prefix+name] = getattr(field.dt, name.lower())
        
    new_df[target_prefix+'Elapsed'] = (field - field.min()).dt.days
    new_df[target_prefix+'MonthName'] = field.dt.month_name()
    new_df[target_prefix+'DayName'] = field.dt.day_name()
    new_df.drop(fieldname, axis=1, inplace=True)

    return new_df