web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Answered

Generating dates

(0) ShareShare
ReportReport
Posted on by 45

Hello,

am working on a report to generate dates of the month...eg from 1st to 31st for jan,,,I have been given an idea of using dataItem but not yet got it

Any code I can read through?

I have the same question (0)
  • Verified answer
    Lars Lohndorf-Larsen Profile Picture
    on at
    RE: Generating dates

    Hello,

    You can use the virtual table "Date". Below is a sample that iterates through january in a codeunit, but you can also specify "Date" as a dataitem in a report. Remember to filter on "Period Type". Here, if you want individual days, then filter it on Date:

    MyDate.setrange("Period Type", MyDate."Period Type"::Date);

    If you wanted the months of the year, you would filter on Month.

    In the sample below, run Business Central with MyServer:8080/.../ then click action "Create Dates", (or run the codeunit somehow else).

    Hope this gets you some ideas.

    Sample code:

    codeunit 50100 GenerateDates

    {

       trigger OnRun()

       begin

           CreateDates(20220101D, 20220131D);

       end;

       local procedure CreateDates(FromDate: Date; ToDate: date)

       var

       begin

           MyDate.setrange("Period Type", MyDate."Period Type"::Date);

           MyDate.setrange("Period Start", FromDate, ToDate);

           if MyDate.FindSet() then

               repeat

                   if not Confirm(format(MyDate."Period Start")) then error('Cancelled.');

               until MyDate.Next() = 0;

       end;

       var

           MyDate: Record Date;

    }

    page 50101 RunMyCodeunit

    {

       PageType = Card;

       ApplicationArea = All;

       UsageCategory = Administration;

       actions

       {

           area(Processing)

           {

               action(CreateDates)

               {

                   Caption = 'Create Dates';

                   Promoted = true;

                   PromotedCategory = Process;

                   PromotedIsBig = true;

                   ApplicationArea = All;

                   trigger OnAction()

                   begin

                       codeunit.run(Codeunit::GenerateDates);

                   end;

               }

           }

       }

       var

           myInt: Integer;

    }

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
Rishabh Kanaskar Profile Picture

Rishabh Kanaskar 4,330

#2
Sumit Singh Profile Picture

Sumit Singh 2,738

#3
Nimsara Jayathilaka. Profile Picture

Nimsara Jayathilaka. 2,546

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans