Date Problem

vikram7_dabasvikram7_dabas Member Posts: 611
Dear Concern
I have 1 employee in Navision in HR Module.I have his "Termination Date" and "Joining Date" fields in Employee Master table.I want to calculate How many Years,Months,Days that Employees works by using these 2 fields.How can I do this?
I format should be like(i.e., 4 Years 10 Months and 28 Days).
Vikram Dabas
Navision Technical Consultant

Comments

  • MalajloMalajlo Member Posts: 294
    Check DATE2DMY (Date) function.

    Then you should code something like
    date1 := 020902D ;
    date2 := 17041975D ;
    message(formaT(calcdate('+'+format(date1-date2)+'D',010101D))) ;
    
    Unfortunately, CALCDATE works only up to 9999 days. :?:
  • vikram7_dabasvikram7_dabas Member Posts: 611
    Dear Concern
    It only Finds Date, but I want Years,Months and Days.I didnt understand ur Logic .Plzz let me know in deep.
    Vikram Dabas
    Navision Technical Consultant
  • SogSog Member Posts: 1,023
    The format type should be like format(281004,0,'<Year> years, <month> months,<day> days')
    just like the help function shows. Now go and find out how to calculate your date trough F1 :)
    |Pressing F1 is so much faster than opening your browser|
    |To-Increase|
  • David_SingletonDavid_Singleton Member Posts: 5,479
    Sog wrote:
    The format type should be like format(281004,0,'<Year> years, <month> months,<day> days')
    just like the help function shows. Now go and find out how to calculate your date trough F1 :)

    It's a pity more people would not read your signature, it might make their life a lot easier. :mrgreen:
    David Singleton
  • byllebylle Member Posts: 47
    Okay - it's time to spell it out for you....

    1) Make sure you inital dates are filled:

      IF ("Termination Date" = 0d) OR ("Joining Date" = 0D) THEN
      ERROR('Missing Date!');

    2) Next calculate number of days between "Termination Date" and "Joining Date":

      NoDays := "Termination Date" - "Joining Date", where NoDays is an Integer

    3) Calculate a new date out from a "zero" date. In this case we are using 01-01-00 as our zero date:

      TempDate := CALCDATE('<+' + NoDays + 'D>', 010100D);

    4) Now that you have calculated a new date you can extract Year, Month and Days:

      Day := DATE2DMY(Tempdate,1); Month := DATE2DMY(Tempdate,2); Year := DATE2DMY(Tempdate,3) - 2000; //2000 = Its the zero date's year and we only wants number of years, and not a complete year. Ex. 2009 vs. 9 ;-)

    Or if you just want's to print/show it:

      MESSAGE(FORMAT(TempDate,0,'<Year> years, <month> months,<day> days');

    If you just want to print/show it - you don't have to calculate TempDate - you can actually do it as a one liner, and thereby skip steps 2 - 3:

      MESSAGE(FORMAT(CALCDATE('<+'+FORMAT("Termination Date" - "Joining Date")+'D>',010100D)),0,'<Year> years, <month> months,<day> days');

    But - that ain't beautiful ;-)
  • David_SingletonDavid_Singleton Member Posts: 5,479
    Dear Concern
    I have 1 employee in Navision in HR Module.I have his "Termination Date" and "Joining Date" fields in Employee Master table.I want to calculate How many Years,Months,Days that Employees works by using these 2 fields.How can I do this?
    I format should be like(i.e., 4 Years 10 Months and 28 Days).

    Just re-reading this, I see that the core issue here is defining the problem. In fact there is not enough information to solve the problem, yet you have already started to look for a code solution. Before you can write the code you need to go to the consultant that wrote this and have them complete the definition.

    Are you communicating directly with the client or via a consultant?
    David Singleton
  • MalajloMalajlo Member Posts: 294
    No, definition of problem is ok, but if I don't have already written code, I usually give a directions how to get problem solved.
Sign In or Register to comment.