Skip to content
Using date filters in Business Central

How-To Use Month Date Filters

Daniel Gorski
Daniel Gorski February 02, 2022
2 min read

What's the case?

You want to create different Date Filters for full months based on today or your workdate?

Dynamics 365 Business Central offers multiple ways to enter dates and times, including powerful features that accelerate data entry, or help you write complex calendar expressions.
Take a look here:
Working with Calendar Dates and Times


If you are using CM = Current month you will discover an issue:

This is our code example, using these variables:

TodayLbl: Label 'Today: %1\\';
PrevMonthLbl: Label 'Previous Month. From: %1 To: %2\\';
ThisMonthLbl: Label 'This Month. From: %1 To: %2\\';
NextMonthLbl: Label 'Next Month. From: %1 To: %2\\';
Next2MonthLbl: Label 'Next 2 Months. From: %1 To: %2\\';
MessageTxt: Text;

And this is our code:

MessageTxt := StrSubstNo(TodayLbl, Today());
MessageTxt += StrSubstNo(PrevMonthLbl, CalcDate('<-CM-1M>', TODAY()), CalcDate('<CM-1M>', TODAY()));
MessageTxt += StrSubstNo(ThisMonthLbl, CalcDate('<-CM>', TODAY()), CalcDate('<CM>', TODAY()));
MessageTxt += StrSubstNo(NextMonthLbl, CalcDate('<-CM+1M>', TODAY()), CalcDate('<CM+1M>', TODAY()));
MessageTxt += StrSubstNo(Next2MonthLbl, CalcDate('<-CM+2M>', TODAY()), CalcDate('<CM+2M>', TODAY()));
Message(MessageTxt);

And this Message will throw:

Message dialog showing the buggy CalcDate output where Previous, Next and Next 2 Months incorrectly end on the 28th instead of each month's actual last day

Not very useful, right?


Are you aware of the PeriodPageManagement Codeunit?

Calendar: Record Date;
PeriodPageMgt: Codeunit PeriodPageManagement;

And this code:

Calendar."Period Start" := CalcDate('<CM-1M>', TODAY());
PeriodPageMgt.FindDate('<', Calendar, Enum::"Analysis Period Type"::Month);
MessageTxt += StrSubstNo(PrevMonthLbl, Calendar."Period Start", Calendar."Period End");

Calendar."Period Start" := CalcDate('<CM>', TODAY());
PeriodPageMgt.FindDate('<', Calendar, Enum::"Analysis Period Type"::Month);
MessageTxt += StrSubstNo(ThisMonthLbl, Calendar."Period Start", Calendar."Period End");

Calendar."Period Start" := CalcDate('<CM+1M>', TODAY());
PeriodPageMgt.FindDate('<', Calendar, Enum::"Analysis Period Type"::Month);
MessageTxt += StrSubstNo(NextMonthLbl, Calendar."Period Start", Calendar."Period End");

Calendar."Period Start" := CalcDate('<CM+2M>', TODAY());
PeriodPageMgt.FindDate('<', Calendar, Enum::"Analysis Period Type"::Month);
MessageTxt += StrSubstNo(Next2MonthLbl, Calendar."Period Start", Calendar."Period End");
Message(MessageTxt);

And this will determine the correct start- and ending dates of each month:

Message dialog showing correct start and end dates for each month after switching to the PeriodPageManagement Codeunit

Happy Coding! đź’ˇ


So you can easily create some cues:

Finance Activities cues on the Role Center showing Orders and Invoices totals broken down by Previous, Current and Next Month

Related posts

â–¸ All posts
Upload and download files via BLOB in Business Central

Upload and Download Files in a BC Blob Field

January 29, 2025 · Daniel Gorski

Learn how to upload and download files in Business Central using a custom AL page and a BLOB field—perfect for storing documents, images, and more.

Read More
Read More: How to Upload and Download Files in a Blob Field in Business Central
SETFILTER issue with special characters in Business Central

Why SETFILTER doesn’t work sometimes

May 04, 2023 · Daniel Gorski

SETFILTER is an AL staple, but it fails silently when the filter string contains special characters like * or @. Here is why, and how STRSUBSTNO fixes it.

Read More
Read More: Why SETFILTER doesn’t work sometimes
Business Central performance tips from BC TechDays

Performance Giveaways

September 19, 2022 · Daniel Gorski

Inspired by Waldo’s BC TechDays 2022 session – discover 5 practical AL coding tips to boost performance in Microsoft Dynamics 365 Business Central.

Read More
Read More: Performance Giveaways