Hello I'm new in here, i want ask for to filterdate

I Have a problem about my filter, i want filter to posting date in same year but different month, like this, if i put the filter range 2023/04/1..2023/04/31 for my filter field show the data about the range, but my code doesnt work, he show the data form my filter untill current month. i wont if i set the filter range the date his show the data the filter? any one help me?

Best Answers

  • ThomasHagenmeyerThomasHagenmeyer Member Posts: 14
    Answer ✓
    Hi GustingurahW,

    welcome to the forum. Please post your code that sets the filter, including the calculation of the minimum and the maximum date of your range.

    Best Regards,
    Thomas
  • ThomasHagenmeyerThomasHagenmeyer Member Posts: 14
    Answer ✓
    Hi GustingurahW,

    You nearly got there already: CM means Current Month, <-CM> yields the first day of the current month, <CM> the last day of the current month. If you want to get the dates for the last month, I'd say:

    StartDate := CalcDate('<-CM-1M>', Today);

    The last day not always is the same , so <CM-1M> won't do the trick. But, the last day of the previous month ist just one day before the first day of the current month, therefore:

    EndDate := CalcDate('<-CM-1D>', Today);

    and then:

    DateFilter.SetRange("Posting Date", StartDate, EndDate);

    Best Regards,
    Thomas

Answers

  • ThomasHagenmeyerThomasHagenmeyer Member Posts: 14
    Answer ✓
    Hi GustingurahW,

    welcome to the forum. Please post your code that sets the filter, including the calculation of the minimum and the maximum date of your range.

    Best Regards,
    Thomas
  • GustingurahWGustingurahW Member Posts: 11
    Hai Thomas Thankyou for the answer, this is my code about the sets filter and the calculation
    trigger OnPreDataItem()
    var
    DateFilter: Record "Item Import CSV";
    StartDate: Date;
    EndDate: Date;
    begin
    // StartDate := CalcDate('<-CM>', Today);
    // EndDate := CalcDate('<CM>', Today);
    // DateFilter.SetRange("Posting Date", StartDate);
    DateFilter.SetFilter("Posting Date", 'MONTH');
    Message(DateFilter.GetFilter("Posting Date"));
    end;
  • ThomasHagenmeyerThomasHagenmeyer Member Posts: 14
    Answer ✓
    Hi GustingurahW,

    You nearly got there already: CM means Current Month, <-CM> yields the first day of the current month, <CM> the last day of the current month. If you want to get the dates for the last month, I'd say:

    StartDate := CalcDate('<-CM-1M>', Today);

    The last day not always is the same , so <CM-1M> won't do the trick. But, the last day of the previous month ist just one day before the first day of the current month, therefore:

    EndDate := CalcDate('<-CM-1D>', Today);

    and then:

    DateFilter.SetRange("Posting Date", StartDate, EndDate);

    Best Regards,
    Thomas
  • GustingurahWGustingurahW Member Posts: 11
    Hi ThomasHagenmeyer,

    Thankyou for the answer,

    may i ask you again?
    i use the code in the pageextension is working, but why i use in create report is not working?
  • GustingurahWGustingurahW Member Posts: 11
    i want filter the data report using filter date to show the data, but if i try this code in the report is not working, filter give me a data until the current month
  • vaprogvaprog Member Posts: 1,140
    Hi GustingurahW

    Again, you did not provide your relevant code. The code works identically on a Page and on a Report, assuming you set the filter on a field of type Date in each object.

    Please use Code-tags for posting your code. It makes it easyer to read, especially if the code is indented.

    Above you used
    DateFilter.SetFilter("Posting Date", 'MONTH');
    
    Please note that this is not a valid filter expression for a Date field. In the client filter text given by the user is translated, before it is used as a filter expression. This translation happens in Codeunit 41 Textmanagement. In code you need to call those functions yourself, or more commonly, use the resulting proper filter expression directly, or using SETRANGE with the proper boundaries calculated using CALCDATE as suggested here.

    I recommand you familiarize yourself with DateFormula expressions by exercise, trying to calculate different DateFormula expressions on different dates.
  • GustingurahWGustingurahW Member Posts: 11
    Hi Vaprog,
    Thankyou For the answer

    about my problem is fixed, i forget type the tag for to my report,, once again i said thanyou so much

    Best Regards,
    GustingurahW
Sign In or Register to comment.