Getting a range from a date type
Saint-Sage
Member Posts: 92
Hello everyone,
I have a field on a request form that is bound to a date type.
I.E. DateRangeRequested as Date
In code I would like to do something similar to this...
IF (NextServiceRange <> 0D) THEN BEGIN
//MinServiceRange := DateRangeRequested[1]; // or whatever
//MaxServiceRange := DateRangeRequested[2]; // or whatever
IF ((NextServiceDate < MinServiceRange) AND (NextServiceDate > MaxServiceRange)) THEN BEGIN
CurrReport.SKIP;
END;
END;
So if the NextServiceRange is not within the date range they specify, it will not print the record.
The problem I am having is I don't know how to reference a compound value in a date type. It is not an array so the above code will not work.
I know I could put two date boxes on the request form, but in that case the user would have to enter the same date twice to enter a single day, which may be the way they use it the report the most.
It seems much more polished if they could simply use one date field and do a range such as 010107..123107, like they do everywhere else in Navision.
Thanks in advance for any help you can give!
I have a field on a request form that is bound to a date type.
I.E. DateRangeRequested as Date
In code I would like to do something similar to this...
IF (NextServiceRange <> 0D) THEN BEGIN
//MinServiceRange := DateRangeRequested[1]; // or whatever
//MaxServiceRange := DateRangeRequested[2]; // or whatever
IF ((NextServiceDate < MinServiceRange) AND (NextServiceDate > MaxServiceRange)) THEN BEGIN
CurrReport.SKIP;
END;
END;
So if the NextServiceRange is not within the date range they specify, it will not print the record.
The problem I am having is I don't know how to reference a compound value in a date type. It is not an array so the above code will not work.
I know I could put two date boxes on the request form, but in that case the user would have to enter the same date twice to enter a single day, which may be the way they use it the report the most.
It seems much more polished if they could simply use one date field and do a range such as 010107..123107, like they do everywhere else in Navision.
Thanks in advance for any help you can give!
No one loves you like the one who created you...
0
Answers
-
Just create a text field for the input DateRangeAsText. On validate of the text field use any date field in any table and:
setfilter("Date field",'%1',DateRangeAsText);
DateRangeAsText := getfilter("date Field");
the create a Record Variable (ServiceDate::Date) of type Date
Servicesate.Setfilter("Date field",'%1&%2',DateRangeAsText,nextservicedate);
if servicedate.findfirst then
date is in range
that code probably wont work, but it will give you the idea of what to do.
I have done this quite often, but off hand I can't find a code snippet to post, so this is just form memory.David Singleton0 -
Okay, Thanks David.
I am actually working off of a derived date, it isn't one stored in a record, otherwise I would just use GETRANGEMAX, GETRANGEMIN.
The other thing is that I am testing a condition as I print out the report from a data item that is not part of my report, and I am not filtering before then, so I can't use a filter to delineate what I am printing.
I know this seems weird but it's because the schema of the database and the exact way the user wants the report to behave don't correspond directly.
I should have specified all that.
I was hoping there was some way to do this without chopping strings but I guess that is what I will have to do!
Thanks for all your help!
No one loves you like the one who created you...0 -
Saint-Sage wrote:Okay, Thanks David.
I am actually working off of a derived date, it isn't one stored in a record, otherwise I would just use GETRANGEMAX, GETRANGEMIN.
The other thing is that I am testing a condition as I print out the report from a data item that is not part of my report, and I am not filtering before then, so I can't use a filter to delineate what I am printing.
I know this seems weird but it's because the schema of the database and the exact way the user wants the report to behave don't correspond directly.
I should have specified all that.
I was hoping there was some way to do this without chopping strings but I guess that is what I will have to do!
Thanks for all your help!
No that's exactly what I understood.
Just to explain the code:setfilter("Date field",'%1',DateRangeAsText); // converts a user entered text string into a normal navision like date filter. DateRangeAsText := getfilter("date Field"); // puts the filter back so the users sees it looking "pretty" i.e. if the user enters 1.1..t the code will return 01.01.07..03.02.07 Servicesate.Setfilter("Date field",'%1&%2',DateRangeAsText,nextservicedate); // this the uses the Date table as a way to work out if the date is in the correct range i.e. the date is both in the range entered by the user, AND the service date is als in the same range. if servicedate.findfirst then // we now do a find on the date table, and if we find a record then the record we find is the service date. date is in range
it works. Try it.
David Singleton0 -
Wow, Thanks!
No one loves you like the one who created you...0 -
\:D/ David Singleton0
Categories
- All Categories
- 75 General
- 75 Announcements
- 66.7K Microsoft Dynamics NAV
- 18.8K 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
- 610 NAV Courses, Exams & Certification
- 1.9K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 251 Dynamics CRM
- 103 Dynamics GP
- 6 Dynamics SL
- 1.5K Other
- 991 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 28 Design Patterns (General & Best Practices)
- Architectural Patterns
- 9 Design Patterns
- 4 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1K General Chat
- 1.6K Website
- 77 Testing
- 1.2K Download section
- 23 How Tos section
- 249 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions
