Julian Date conversion question

SaidSaid Member Posts: 20
edited 2007-03-05 in Navision Attain
Hi,

Does anyone know how to convert a Julian Date (eg. 731578) into Navision date field format?

Thanks in advance

Comments

  • jreynoldsjreynolds Member Posts: 175
    Add the Julian date to whatever the base date is for your Julian calendar. For example, 01010000D + 731578 produces 12292002D.
  • Timo_LässerTimo_Lässer Member Posts: 481
    That's interesting.
    Does anybody know the base date for the Julian calendar?
    Timo Lässer
    Microsoft Dynamics NAV Developer since 1997
    MSDynamics.de - German Microsoft Dynamics Community - member of [clip]
  • kinekine Member Posts: 12,562
    Look at http://www.tondering.dk/claus/cal/node3 ... 0000000000

    there are formulas to calc from gregorian to julian and back...

    or use convertor on http://www.fourmilab.ch/documents/calendar/
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • SaidSaid Member Posts: 20
    Thank you for all replies.
    But when I'm setting the refDate - I got the message that the refDate is not a valid date... What am I doing wrong?


    Expr1 := 'CQ+1M-10D'; // Current quarter + 1 month - 10 days
    Expr2 := '-WD2'; // The last weekday no.2, (last Tuesday)
    Expr3 := 'CM+30D'; // Current month + 30 days
    RefDate := 12292002D;
    Date1 := CALCDATE(Expr1, RefDate);
    Date2 := CALCDATE(Expr2, RefDate);
    Date3 := CALCDATE(Expr3, RefDate);
    MESSAGE(Text000 + Text001 + Text002 + Text003,
    RefDate, Expr1, Date1, Expr2, Date2, Expr3, Date3);
  • kinekine Member Posts: 12,562
    tray 122902D
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • SaidSaid Member Posts: 20
    Just tried...Still no luck. Same error - not a valid date...
  • kinekine Member Posts: 12,562
    ahhh... yes, I overlooked it - you must enter 29122002D --- it is ddmmyyyy... :D
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • Timo_LässerTimo_Lässer Member Posts: 481
    Has anyone created a codeunit with Julian2Gregorian and Gregorian2Julian?
    Timo Lässer
    Microsoft Dynamics NAV Developer since 1997
    MSDynamics.de - German Microsoft Dynamics Community - member of [clip]
  • Timo_LässerTimo_Lässer Member Posts: 481
    Has anyone created a codeunit with Julian2Gregorian and Gregorian2Julian?

    Now, I have created such functions:
    JulianDayNo2GregorianDate(JulianDate : Integer) : Date
    
    JulianDayNo2JulianDate(JulianDate : Integer) : Date
    
    GregorianDate2JulianDayNo(GregorianDate : Date) : Integer
    
    JulianDate2JulianDayNo(JulianDate : Date) : Integer
    

    The functions are availible as download here:
    http://www.msdynamics.de/dload.php?acti ... file_id=68

    (I hope, it doesn't matter that the website is in german ;-) )
    Timo Lässer
    Microsoft Dynamics NAV Developer since 1997
    MSDynamics.de - German Microsoft Dynamics Community - member of [clip]
  • SavatageSavatage Member Posts: 7,142
    DateToJulian(CalcDate : Date) : Decimal
    Day := DATE2DMY(CalcDate,1);
    Month := DATE2DMY(CalcDate,2);
    Year := DATE2DMY(CalcDate,3);
    
    IF Year < 100 THEN
      ERROR('At least four digit year required.');
    IF (Month < 1) OR (Month > 12) THEN
      ERROR('Invalid Month');
    IF (Day < 1) OR (Day > 31) THEN
      ERROR('Invalid Day');
    
    TempInt := (Month - 14) DIV 12;
    JulianDate := Day - 32075 + (1461 * (Year + 4800 + TempInt) DIV 4);
    JulianDate := JulianDate + (367 * (Month - 2 - TempInt * 12) DIV 12);
    JulianDate := JulianDate - (3 * ((Year + 4900 + TempInt) DIV 100) DIV 4);
    
    EXIT(JulianDate);
    

    JulianToDate(JulianDate : Decimal) : Date
    l := JulianDate + 68569.0;
    n := (4 * l) DIV 146097;
    l := l - ((146097 * n + 3) DIV 4);
    i := (4000 * (l + 1)) DIV 1461001;
    l := l - ((1461 * i) DIV 4) + 31;
    j := (80 * l) DIV 2447;
    k := l - (2447 * j) DIV 80;
    l := j DIV 11;
    j := j + 2 - 12 * l;
    i := 100 * (n - 49) + i + l;
    Year := i DIV 1;
    Month := j DIV 1;
    Day := k DIV 1;
    
    EXIT(DMY2DATE(Day,Month,Year));
    
  • james_csjames_cs Member Posts: 39
    
    Date2YYDDD(DateIn : Date) YYDDD : Code[5]
    Year:=DATE2DMY(DateIn,3);
    Day := DateIn - CALCDATE('-CY',DateIn) +1;
    YYDDD:=COPYSTR(FORMAT(Year),3,2);
    YYDDD:=YYDDD+FORMAT(Day,3);
    YYDDD:=CONVERTSTR(YYDDD,' ','0');
    
Sign In or Register to comment.