How do I turn a month into a date with Period and to_timestamp?

Turn a month, such as a momentum strategy’s formation month, into its last calendar day with to_timestamp, move dates to month ends with offsets, and see why the last weekday can differ from the last trading session.

After this lesson, you can turn a month into its last calendar day and its last trading session.

How do I turn a month into its last day?

A Period is a whole interval, such as January 2026, while a Timestamp is one moment, so a month needs a rule to become a date. .to_timestamp(how="end") takes the last moment of the month, one nanosecond before February, and .normalize() sets it to midnight, which gives 31 January as the month’s date.

pd.Period("2026-01", freq="M") makes a monthly Period, and adding 1 moves it by one month. On a column of dates, .dt.to_period("M") gives each date’s month, and .dt.to_timestamp(how="end").dt.normalize() turns a column of months into their last days.

The following box converts January both ways.

import pandas as pd

january = pd.Period("2026-01", freq="M")
print(january, january + 1)
print(january.to_timestamp(how="start"), january.to_timestamp(how="end"))
print(january.to_timestamp(how="end").normalize())
2026-01 2026-02
2026-01-01 00:00:00 2026-01-31 23:59:59.999999999
2026-01-31 00:00:00

pd.to_datetime(january) raises a TypeError, and pd.to_datetime(str(january)) reads the text as 1 January.

How do I move a date to a month end?

pd.offsets.MonthEnd(0) moves a date forward to the end of its month and keeps a date already there, while MonthEnd(1) always moves to the next month end. From 31 January, MonthEnd(0) stays and MonthEnd(1) reaches 28 February. pd.offsets.BMonthEnd(0) moves to the month’s last weekday, Friday 30 January.

The following box adds the three offsets to 1 and 31 January.

days = pd.Series(pd.to_datetime(["2026-01-01", "2026-01-31"]))
print(pd.DataFrame({
    "day": days,
    "month_end_0": days + pd.offsets.MonthEnd(0),
    "month_end_1": days + pd.offsets.MonthEnd(1),
    "last_weekday": days + pd.offsets.BMonthEnd(0),
}))
         day month_end_0 month_end_1 last_weekday
0 2026-01-01  2026-01-31  2026-01-31   2026-01-30
1 2026-01-31  2026-01-31  2026-02-28   2026-02-27

From Saturday 31 January, BMonthEnd(0) has passed the month’s last weekday and reaches 27 February, so a month’s last weekday is best found from its first day.

Why can the last trading session differ?

A month’s last weekday can be an exchange holiday, so the last trading session comes from the exchange calendar. On a made-up exchange closed on Friday 27 February 2026, the month’s returns end on Thursday 26 February, while the weekday rule gives 27 February.

The returns are a made-up stock’s monthly returns in percent, each dated by its last session. The lesson on the trading calendar builds a real exchange’s sessions.

The following box compares the weekday rule with the sessions.

returns = pd.DataFrame({"session": pd.to_datetime(["2026-01-30", "2026-02-26"]), "return_pct": [2.0, 1.5]})
returns["month"] = returns["session"].dt.to_period("M")
returns["last_weekday"] = returns["month"].dt.to_timestamp(how="start") + pd.offsets.BMonthEnd(0)
returns["last_day"] = returns["month"].dt.to_timestamp(how="end").dt.normalize()
print(returns)
     session  return_pct    month last_weekday   last_day
0 2026-01-30         2.0  2026-01   2026-01-30 2026-01-31
1 2026-02-26         1.5  2026-02   2026-02-27 2026-02-28

Your turn

Print the last calendar day of February 2026 from its Period. You should see 2026-02-28.

january + 1 is February.

print((january + 1).to_timestamp(how="end").normalize().date())
2026-02-28