std : 기준일 

mth_bdt : 기준일 월 첫 날짜

mth_edt : 기준일 월 마지막 날짜

 

from datetime import datetime

for d in range(10):

    std = (datetime.strptime('20240201', '%Y%m%d') + timedelta(days = d)).strftime('%Y%m%d')

    mth_bdt = (pd.to_datetime(std, format = '%Y%m%d').replace(day = 1).strftime('%Y%m%d')

    mth_edt = (pd.to_datetime(std, format = '%Y%m%d') + pd.offsets.MonthEnd(0)).strftime('%Y%m%d')

    print(f"std: {std}, mth_bdt : {mth_bdt}, mth_edt : {mth_edt}")

 

반응형

+ Recent posts