What is the precise definition of JDE's Julian Date format?

后端 未结 8 658
清歌不尽
清歌不尽 2020-12-03 18:02

I am writing code to convert from a Gregorian date to a JDE (J.D.Edwards) Julian date.

Note: a JDE Julian date is different from the normal usag

8条回答
  •  一整个雨季
    2020-12-03 18:14

    A sample of VBA code to convert back and forth between JDE Julian Date and Gregorian:

    Public Const Epoch = 1900
    Public Const JDateMultiplier = 1000
    Public Const FirstJan = "01/01/"
    
    Public Function Julian2Date(ByVal vDate As Long) As Date
    
        Dim Year As Long
        Dim Days As Long
        Dim SeedDate As Date
    
        '   Day Number
        Days = vDate - (Int(vDate / JDateMultiplier) * JDateMultiplier) - 1
        '   Calendar Year
        Year = ((vDate - Days) / JDateMultiplier) + Epoch
        '   First Day of Calendar Year
        SeedDate = CDate(FirstJan + CStr(Year))
    
        '   Add Number of Days to First Day in Calendar Year
        Julian2Date = DateAdd("d", Days, SeedDate)
    
    End Function
    
    Public Function Date2Julian(ByVal vDate As Date) As Long
    
        Dim JYear As String
        Dim BeginDate As Date
        Dim JDays As Long
    
        '   Calendar Year
        JYear = Format(Year(vDate), "0000")
        '   First Day of Calendar Year
        BeginDate = CDate(FirstJan + JYear)
        '   Day Number
        JDays = DateDiff("d", BeginDate, vDate) + 1
    
        '   Add Number of Days to Year Number
        Date2Julian = ((CLng(JYear) - Epoch) * JDateMultiplier) + JDays
    
    End Function
    

    I have tried to make it as clear and simple as possible, and to this end I have intentionally left out any error trapping. However, you should be able to add the code to a VBA module and call them directly from your own code.

    I also include some useful snippets of T-SQL:

    Todays Date as JDE Julian Date:

     (datepart(yy,getdate())-1900) * 1000 + datepart(dy, getdate())
    

    Convert JDE Julian Date to Gregorian (DD/MM/YYYY), replace XXXXXX with the column name containing the JDE Julian Date:

    convert (varchar, dateadd (day,convert (int, right(XXXXXX,3)) - 1, convert (datetime, ('1/1/' + convert ( varchar, (cast(left(right(XXXXXX+1000000,6),3) as varchar) + 1900))))),103)
    

    If you require a different Gregorian format, replace the 103 value (right at the end) with the applicable value found here: https://msdn.microsoft.com/en-us/library/ms187928.aspx

提交回复
热议问题