Get Current month as filter

anden
Member Posts: 6
Hello everybody
I am having some difficulties with filters in my C/AL code.I have utilized CU1 and the makedatefilter, but e.g. 'CM' is not accepted by it...
I'm wondering if there is any other way to achieve this - and how can I be able to i.e. go to the month after the month i have in my current filter?
I hope that some one here can provide me with the golden answer.
I am having some difficulties with filters in my C/AL code.I have utilized CU1 and the makedatefilter, but e.g. 'CM' is not accepted by it...
I'm wondering if there is any other way to achieve this - and how can I be able to i.e. go to the month after the month i have in my current filter?
I hope that some one here can provide me with the golden answer.
0
Answers
-
Maybe this piece of code will put you on the right track:
this will filter on the month after your current month.yourdate := WORKDATE; startdate := CALCDATE('+1M', yourdate); enddate := CALCDATE('+2M',yourdate); enddateDay := 1; enddatemonth := DATE2DMY(enddate,2); enddateyear := DATE2DMY(enddate,3); enddate := DMY2DATE(enddateday,enddatemonth,enddateyear); enddate := CALCDATE('-1D',enddate); startdateday := 1; startdatemonth := DATE2DMY(startdate,2); startdateyear := DATE2DMY(startdate,3); Startdate := DMY2DATE(startdateday,startdaymonth,startdayyear); yourtable.SETRANGE(yourdatevariable,startdate,enddate);
hope this helps,
WillyFostering a homeless, abused child is the hardest yet most rewarding thing I have ever done.1 -
Hi,
.... or you can use the virtual table date 2000000007, type Month and filter/find by date.0 -
There are some way's.
for example using calcdate:message(format(CALCDATE('<-CM>',today)) + '..' + format(calcdate('<CM>',today)));
Or using the virtual table date:Date.reset; Date.setrange("Period Type",Date."Period Type"::Month); Date.setfilter("Period Start",'<=%1',today); Date.findlast; message(format(Date."Period Start") + '..' + format(Date."Period End"));
RegardsDo you make it right, it works too!0 -
So to elaborate a little on that:
CALCDATE('<-CM>',TODAY) will get you the FIRST date of the month in TODAY
CALCDATE('<CM>',TODAY) will get you the LAST date of the month for TODAY
So to get this month's first/last days and next month's first/last days:ThisMonthFirst := CALCDATE('<-CM>',today); ThisMonthLast := CALCDATE('<CM>',ThisMonthFirst); NextMonthFirst := CALCDATE('<+1D>,ThisMonthLast); NextMonthLast := CALCDATE('<CM>',NextMonthFirst);
No need to get into the date table for this particular one in my opinion, although that would also be a very good solution. If you want to get more generic though, the date table is very handy for date processing. You should definately look at it and see how it works, which options are available. Create a new form, put all the fields on there and filter on it. Take a look at the Base Calendar logic in base NAV to see some examples of how it is used.0 -
Thank you all for your inputs, and thank you DenSter and Garak for the help, it works like a charm. =D>
Again, thank you
Best regards
Anden0 -
Please, and welcome to mibuso ;-)Do you make it right, it works too!0
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