Previous month dates

Hello

I want to get the first and last dates of a month based on today’s date. For February, it should return 01-02-2026 and 28-02-2026, and the logic should also correctly handle leap years.

Hi @Paul_Mark

Kindly look into the below expression

First Date of the previous month

New DateTime(Now.Year,Now.Month,1).AddMonths(-1).ToString(“dd/MM/yyyy”)

Last Date of the previous month

New DateTime(Now.Year,Now.Month,1).AddDays(-1).ToString("dd/MM/yyyy")

Regards,
Gokul

2 Likes

Hi @Paul_Mark,

Use these VB.NET expressions in Assign activities for previous month’s first/last dates.
Handles leap years automatically via .NET DateTime.

Assign Activities

FirstPrev = New DateTime(Now.Year, Now.Month, 1).AddMonths(-1).ToString("dd-MM-yyyy")
LastPrev = New DateTime(Now.Year, Now.Month, 1).AddDays(-1).ToString("dd-MM-yyyy")

For Jan 7, 2026: “01-12-2025” to “31-12-2025”.

1 Like

Hi,

FYI, another solution: using ModifyDate activity.


note: Please replace New Date(2026,2,10) with Now if you want to calculate it based actual today’s date.

Sample
Sample20260107-2.zip (3.6 KB)

Regards,

6 Likes

Hi @Paul_Mark

You can get the first and last date of the current month using built-in .NET functions, no need to handle leap years manually.

First date of the month:

New DateTime(Now.Year, Now.Month, 1)

Last date of the month:

New DateTime(Now.Year, Now.Month, Date.DaysInMonth(Now.Year, Now.Month))

If the month is February 2026, it will return 01-02-2026 and 28-02-2026. For leap years, Date.DaysInMonth automatically returns 29, so the logic works correctly.

1 Like

Hi @Paul_Mark

You can also check for the same :slight_smile:

Happy Automation

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.