Rerturn a negative date.

anton1987anton1987 Member Posts: 35
Hi everyone

Hope everyone is all good.

I have the following code


IF WORKDATE < "Purchase Line"."Expected Receipt Date" THEN
NoOfDays := FORMAT("Purchase Line"."Expected Receipt Date"-WORKDATE);

When this code is run It does not return a negative date. It just makes the date value equal to 'BLANK'. Am I doing something wrong.

Comments

  • David_SingletonDavid_Singleton Member Posts: 5,479
    anton1987 wrote:
    Hi everyone

    Hope everyone is all good.

    I have the following code


    IF WORKDATE < "Purchase Line"."Expected Receipt Date" THEN
    NoOfDays := FORMAT("Purchase Line"."Expected Receipt Date"-WORKDATE);
    When this code is run It does not return a negative date. It just makes the date value equal to 'BLANK'. Am I doing something wrong.

    [code]
    you have your logic backwards. The second line wont execute if its negative.
    David Singleton
  • anton1987anton1987 Member Posts: 35
    Ok but when I say

    If WD <> ERD then
    No.Of.Days := ( ERD - WD);

    I get an error message saying that date is not valid
  • mohana_cse06mohana_cse06 Member Posts: 5,504
    anton1987 wrote:
    Ok but when I say

    If WD <> ERD then
    No.Of.Days := ( ERD - WD);

    I get an error message saying that date is not valid

    what is DataType of No.Of.Days
  • anton1987anton1987 Member Posts: 35
    No.Of days is a text var

    and the function is
    IF WD <> ERD THEN
    No.Of Days := FORMAT(ERD-WD);
  • mohana_cse06mohana_cse06 Member Posts: 5,504
    ERD := "Purchase Header"."Expected Receipt Date";
    WD := WORKDATE;
    if ERD <> WD then
      "No.Of.Days"  := format(ERD-WD);
    message('%1',"No.Of.Days");
    

    Name	DataType	Subtype	Length
    ERD	Date		
    WD	Date		
    No.Of.Days	Text		30
    

    I am not getting any error.
  • anton1987anton1987 Member Posts: 35
    Thanks Man you are a legend.
    Thanks for all the help works like a charm
  • mohana_cse06mohana_cse06 Member Posts: 5,504
    anton1987 wrote:
    Thanks Man you are a legend.
    Thanks for all the help works like a charm

    welcome and thanks for ur comment
  • Slawek_GuzekSlawek_Guzek Member Posts: 1,690
    anton1987 wrote:
    If WD <> ERD then
    No.Of.Days := ( ERD - WD);

    I get an error message saying that date is not valid
    1. You can't have 'negative' date - minimal value in Date type variable is 0D (blank date)
    2. You can't do any math with blank dates
    3. Subststracting two dates gives you integer - number of dates between two dates

    So if you're getting error messages it means that either ERD, or WD, or both are blank dates. In your case "Purchase Header"."Expected Receipt Date" must be blank

    Regards,
    Slawek
    Slawek Guzek
    Dynamics NAV, MS SQL Server, Wherescape RED;
    PRINCE2 Practitioner - License GR657010572SG
    GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-03
Sign In or Register to comment.