How to compair two date fields

vyankuvyanku Member Posts: 791
I want to compair two dates like
IF "Purch. Rcpt. Line"."Promised Receipt Date" <= "Purch. Rcpt. Line"."Receipt Date" THEN
BEGIN
qty := "Purch. Rcpt. Line"."Total recived";
END
ELSE
BEGIN
qty1 := "Purch. Rcpt. Line"."Total recived";
END;

But If one of the date is zero then only the loop is going to be executed correctly .If both date fields contains date then only first part of loop will execute in any condition.

Why this happend??
How can I compair two date fields??

Answers

  • ServalServal Member Posts: 51
    vyanku wrote:
    How can I compair two date fields??
    This is a good way to compare two dates.

    Check that the dates are correctly filled in "Purch. Rcpt. Line" table...
  • diptish.naskardiptish.naskar Member Posts: 360
    IF "Purch. Rcpt. Line"."Promised Receipt Date" <= "Purch. Rcpt. Line"."Receipt Date" THEN
    BEGIN
    qty := "Purch. Rcpt. Line"."Total recived";
    END
    ELSE
    BEGIN
    qty1 := "Purch. Rcpt. Line"."Total recived";
    END;

    Seems correct to me also...do check the dates in the table.
    Diptish Naskar
    For any queries you can also visit my blog site: http://msnavarena.blogspot.com/
  • DenSterDenSter Member Posts: 8,307
    vyanku wrote:
    I want to compair two dates like
    IF "Purch. Rcpt. Line"."Promised Receipt Date" <= "Purch. Rcpt. Line"."Receipt Date" THEN
    BEGIN
    qty := "Purch. Rcpt. Line"."Total recived";
    END
    ELSE
    BEGIN
    qty1 := "Purch. Rcpt. Line"."Total recived";
    END;
    

    But If one of the date is zero then only the loop is going to be executed correctly .If both date fields contains date then only first part of loop will execute in any condition.

    Why this happend??
    How can I compair two date fields??
    What do you mean 'loop'? there's no loop in your code. If both dates are zero then they are the same and therefore the expression evaluates to TRUE and it will therefore execute the TRUE part of your IF statement. What is wrong about that?
  • jmjm Member Posts: 156
    Perhaps this may be a solution:
    IF ("Purch. Rcpt. Line"."Promised Receipt Date" <> 0D) AND 
       ("Purch. Rcpt. Line"."Promised Receipt Date" <= "Purch. Rcpt. Line"."Receipt Date") 
    THEN BEGIN 
      qty := "Purch. Rcpt. Line"."Total recived"; 
    END ELSE BEGIN 
      qty1 := "Purch. Rcpt. Line"."Total recived"; 
    END;
    
    if not, you have to explain more detailed, what you want the code to do.
    How can I compair two date fields??
    You can compair two date fields in that way you did, but you have to consider that an empty date is the lowest date ever.
    br
    Josef Metz
  • adamEthanadamEthan Member Posts: 104
    This is the code I used, which probably looks a lot like everything else posted:
    IF ("sales shipment header"."Shipment Date" <> 0D) AND
    ("Planned Shipment Date" <> 0D) THEN BEGIN
    OnTime := "sales shipment header"."Shipment Date" - "Planned Shipment Date";
  • vyankuvyanku Member Posts: 791
    I just want to compair two dates like
    IF 01-01-07<= 10-01-07 THEN
    BEGIN
    qty := "Purch. Rcpt. Line"."Total recived";
    END
    ELSE
    BEGIN
    qty1 := "Purch. Rcpt. Line"."Total recived";
    END;

    here if the value of first date is zero then only it execute the else part
    If it is not zero then it executes only if part even it the date is 15-01-07.
    This is my main problem.
    I wanted to create report for vendor performance.In that report there are two columns .If the quantity is recived within the time i.e.within promice date and posting date the the quantity should be appeare in first column else it should be appear in another column.
  • ServalServal Member Posts: 51
    vyanku,
    Your code is correct. The problem seem to be elsewhere.
    In wich trigger of the report did you put the code ?
  • vyankuvyanku Member Posts: 791
    "Purch. Rcpt. Line" OnAfterGetRecord()
  • vyankuvyanku Member Posts: 791
    anybody please suggest [-o<
  • DenSterDenSter Member Posts: 8,307
    Something like this:
    IF ("Purch. Rcpt. Line"."Promised Receipt Date" = 0D) OR
       ("Purch. Rcpt. Line"."Receipt Date" =0D) THEN BEGIN
      //Do what you need to do if one of the dates is zero
    END ELSE BEGIN
      IF "Purch. Rcpt. Line"."Promised Receipt Date" <= "Purch. Rcpt. Line"."Receipt Date" THEN BEGIN
        qty := "Purch. Rcpt. Line"."Total recived";
      END ELSE BEGIN
        qty1 := "Purch. Rcpt. Line"."Total recived";
      END;
    END;
    
    Is that what you mean?
  • vyankuvyanku Member Posts: 791
    No.
    Can we compair dates like this
    if 01-01-07 < 02-01-07 then
    .....??
    or
    if first date is older i.e. smaller than second date then ...
    Is it possible in navision??? How??
    If my code is correct then why it executes only if part of the loop?? why not else loop even when I insert date smaller or greater than the recipt date???
  • DenSterDenSter Member Posts: 8,307
    The computer is very dumb, it can only do exactly what you tell it to do. It executes the TRUE part of your IF statement because your expression evaluates to TRUE. That is all there is to it.

    Let me say that again: Your expression evaluates to TRUE, and therefore the TRUE part of your IF statement is executed.

    If it doesn't do what you want it to do, then you rewrite the expresion in such a way that it evaluates to TRUE on your conditions, there's nothing else I can say about that.

    If you don't understand the difference between true and false, or how to write a line of code to evaluate a condition, then it is probably time you found another line of work.
  • DenSterDenSter Member Posts: 8,307
    vyanku wrote:
    Can we compair dates like this
    if 01-01-07 < 02-01-07 then
    .....??
    or
    if first date is older i.e. smaller than second date then ...
    Is it possible in navision??? How??
    Yes it is possible, and that is how you do it. If you want to know if date1 is before date2, you program it that way: IF Date1 < Date2 THEN...

    You need to think about your code and rewrite it so that it does what you want it to do. Right now you're just asking the same question over and over.
  • vyankuvyanku Member Posts: 791
    Thanks.
    My problem is solved.
    Thanku very much.
  • himanshuhimanshu Member Posts: 24
    I am also facing the same problem please help me.
    Thanks&Regards
    Himanshu Yadav
    (Dynamics NAV)
  • ppavukppavuk Member Posts: 334
    i think the most polite answer i can offer - RTFM. Google for RTFM if you don't know what is it.
  • kirantakiranta Member Posts: 2
    Your code is correct. The problem seem to be elsewhere.
    In wich trigger of the report did you put the code ?
    ________________
    daily deals, online shopping sites, hot deals, best deals
Sign In or Register to comment.