Getting a range from a date type

Saint-Sage
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!

No one loves you like the one who created you...

Answers

  • David_Singleton
    David_Singleton Member Posts: 5,479
    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 Singleton
  • Saint-Sage
    Saint-Sage Member Posts: 92
    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...
  • David_Singleton
    David_Singleton Member Posts: 5,479
    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. :mrgreen:
    David Singleton
  • Saint-Sage
    Saint-Sage Member Posts: 92
    Wow, Thanks! :lol:

    No one loves you like the one who created you...
  • David_Singleton
    David_Singleton Member Posts: 5,479
    :mrgreen: \:D/
    David Singleton