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

GustingurahW
Member Posts: 11
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?
0
Best Answers
-
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,
Thomas0 -
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,
Thomas0
Answers
-
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,
Thomas0 -
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;0 -
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,
Thomas0 -
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?
0 -
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 month0
-
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 usedDateFilter.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.0 -
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,
GustingurahW0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions