problem with dates

roshanthaparoshanthapa Member Posts: 90
How can I apply a filter to a recordset through cal code, I tried something like this:

recordset.setfilter("date_field",date filter);

the error is triggered and says:

"Type conversion is not possible because 1 of the operators contains an invalid type

Text := Date"

i understood the errror that data-type is not compatible, however the date_field is not of type text but date only. How can I rectify this?

Another thing is that if the date specified is a dataformula like 01/01/07..12/31/07, how can I get the date '12/31/06' that is just a day before the specified filter. Please enlighten me.......


-Roshan Thapa

Comments

  • AlbertvhAlbertvh Member Posts: 516
    Hi

    do the following
    recordset.setfilter("date_field",'%1',date filter); 
    
    or
    
    recordset.setfilter("date_field",'%1..%2',date1,date2); 
    
  • roshanthaparoshanthapa Member Posts: 90
    Actually I am talking that date from a field in report. When I enter "010107..123107", the compiler says "is not a valid date". i also want to get the date of day before the period start date i.e. 123106.
  • WaldoWaldo Member Posts: 3,412
    I don't understand exactly what you're trying to do.

    If you want to filter a date, there are a few options:
    SETFILTER: use the way Albert showed you


    I'm guessing you're stuck with this:
    If you want to give a date filter through a request form, you can create a text variable, and OnValidate of the textbox:
    recsalesheader.SETFILTER("Document Date",txtDateFilter);
    txtDateFilter := recsalesheader.GETFILTER("Document Date");
    
    This way, you can give in 010107..311207 in the textbox (variable: txtDateFilter), and it'l make it 01/01/07..31/12/07 .

    Why recSalesHeader? because you need a field to filter on (to use SETFILTER).

    May be not a nice way to do it, but it is a way ...

    Eric Wauters
    MVP - Microsoft Dynamics NAV
    My blog
  • AlbertvhAlbertvh Member Posts: 516
    1) Check your date format maybe it's ddmmyy and not mmddyy
    2) to get the previous date use the CALCDATE function

    PrevDate := CALCDATE('<-1Y>',GETRANGEMAX("Dater Filter"));

    <Edit>
    PrevDate := CALCDATE('<-1D>',GETRANGEMIN("Dater Filter"));
    <End Edit>
  • roshanthaparoshanthapa Member Posts: 90
    Thanx Waldo, this is exactly what I wanted to do. Now can we get the date of day before minimum range valued date? Since it is a text, I think calcfield won't work, will it?


    Thankx guys(Albert and Waldo)

    -Roshan
  • WaldoWaldo Member Posts: 3,412
    No problem 8) .

    Can you be more specific? Example or something?

    Don't forget you can use the virtual table "date" as well to do some date-tricks.

    Eric Wauters
    MVP - Microsoft Dynamics NAV
    My blog
  • AlbertvhAlbertvh Member Posts: 516
    CALCDATE and use GETRANGEMIN will work if you use the rec date field.

    Did you sort out your compile error for incorrect date?
  • roshanthaparoshanthapa Member Posts: 90
    Albert, I have solved my problem.////////////////THANX
    Thanks Waldo to you too.

    without ur assistance, it would have been hard to solve my problem.....Thanx again
  • WaldoWaldo Member Posts: 3,412
    No problem, dude 8) .

    Can you put [solved] in the subject?

    Eric Wauters
    MVP - Microsoft Dynamics NAV
    My blog
  • roshanthaparoshanthapa Member Posts: 90
    recsalesheader.SETFILTER("Document Date",Datefilter);
    Datefilter := recsalesheader.GETFILTER("Document Date");
    lastdate := recsalesheader.GETRANGEMIN("Document Date");
    lastdate := CALCDATE('<-1D>',lastdate);
Sign In or Register to comment.