[RESOLVED] Converting Gregorian to JDE Julian & back-VBForums
Results 1 to 7 of 7

Thread: [RESOLVED] Converting Gregorian to JDE Julian & back

  1. #1

    Thread Starter
    PowerPoster JuggaloBrotha's Avatar
    Join Date
    Sep 2005
    Location
    Lansing, MI; USA
    Posts
    3,817

    Resolved [RESOLVED] Converting Gregorian to JDE Julian & back

    I'm looking to be able to create a small .Net program that would allow me to convert a Gregorian calendar date to a Julian date and visa versa. For example today (6-April-2012) Gregorian is 112097 Julian. The Julian date structure is:

    1 digit for the century
    2 digits for the current year
    3 digits for the current day of the year

    I've tried a few online converters but they show today as being 2456023.5 Julian, but all of the records for this morning in the JDE inventory tracking program at work says today is 112097, so I would like to make my own program rather than using an online converter.
    Last edited by JuggaloBrotha; Jan 28th, 2013 at 01:47 PM.

  2. #2

    Thread Starter
    PowerPoster JuggaloBrotha's Avatar
    Join Date
    Sep 2005
    Location
    Lansing, MI; USA
    Posts
    3,817

    Re: Converting Gregorian to JDE Julian & back

    Ok, I've done some playing with it and it looks like I simply parse the year:
    For the century I take the 2nd digit in the year and I add 1 to it, so for 2012 I take the 0 and add 1.
    For the current year, I just take the last 2 digits from the year, which is the 12.
    For the day of the year, luckily .Net's Date object has a DayOfYear property I can use, which for today returns "97", all I have to do is format it in a "###" fasion so 97 shows as 097.

    Now the hard part, taking "112097" and parsing it into a "06/04/2012" date.
    Last edited by JuggaloBrotha; Jan 28th, 2013 at 01:47 PM.

  3. #3
    New Member
    Join Date
    Jan 2013
    Posts
    3

    Re: [RESOLVED] Converting Gregorian to Julian & back

    can you please post the program, i am really interested please

  4. #4
    New Member
    Join Date
    Jan 2013
    Posts
    3

    Re: Converting Gregorian to Julian & back

    can you please post the program, i am really interested please

  5. #5
    PowerPoster
    Join Date
    May 2002
    Posts
    25,298

    Re: [RESOLVED] Converting Gregorian to Julian & back

    drop the century digit... take the year, use it to build the date 1/1 for that year... then use the DateAdd (or .AddDays if using .NET) to add the number of days (less 1) to the 1/1 date... that should then return the correct date.

    -tg

    Juggalo - Hold on a moment there.... in your post, you said:
    "For the century I take the 3rd digit in the year and I add 1 to it, so for 2012 I take the 0 and add 1." -- but isn't the third digit "1" ?? 2-0-1-2 ... or did you mean the "second" digit in the year?

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  6. #6

    Thread Starter
    PowerPoster JuggaloBrotha's Avatar
    Join Date
    Sep 2005
    Location
    Lansing, MI; USA
    Posts
    3,817

    Re: [RESOLVED] Converting Gregorian to JDE Julian & back

    Quote Originally Posted by rlawoo View Post
    can you please post the program, i am really interested please
    The Julian date I was needing is a JDE Julian date and not a true Julian date, fyi:
    vb Code:
    1. #Region " Date Conversions: GetGregorianDate, GetJDEDate "
    2.  
    3.     Private Function GetGregorianDate(ByVal JDEDate As String) As Date
    4.         Dim GregDate As Date = DateTime.Today
    5.         JDEDate = JDEDate.Trim
    6.         If JDEDate.Length > 0I AndAlso Long.TryParse(JDEDate, New Long) Then
    7.             Dim DayOfYearStr As String = If(JDEDate.Length > 3I, JDEDate.Substring(JDEDate.Length - 3I, 3I), JDEDate)
    8.             If JDEDate.Length > 3I Then
    9.                 JDEDate = JDEDate.Substring(0I, JDEDate.Length - 3I)
    10.                 Dim YearStr As String = If(JDEDate.Length > 2I, JDEDate.Substring(JDEDate.Length - 2I, 2I), JDEDate)
    11.                 If JDEDate.Length > 2I Then
    12.                     JDEDate = JDEDate.Substring(0I, JDEDate.Length - 2I)
    13.                     Dim Century As Integer = CInt(JDEDate) + 19I
    14.                     GregDate = New Date(CInt(Century.ToString & YearStr), 1I, 1I)
    15.                 Else
    16.                     'No century was provided
    17.                     GregDate = New Date(CInt("19" & CInt(YearStr).ToString("00")), 1I, 1I)
    18.                 End If
    19.             Else
    20.                 'DayOfYear is all that was provided
    21.                 GregDate = New Date(m_MinDate.Year, m_MinDate.Month, m_MinDate.Day)
    22.             End If
    23.             GregDate = GregDate.AddDays(CInt(DayOfYearStr) - 1I)
    24.         End If
    25.         Return GregDate
    26.     End Function
    27.  
    28.     Private Function GetJDEDate(ByVal GregorianDate As Date) As String
    29.         Return String.Format("{0}{1}{2}", If(GregorianDate.Year < 2000I, String.Empty, CStr(CInt(GregorianDate.Year.ToString.Substring(1I, 1I)) + 1I)), GregorianDate.Year.ToString.Substring(2I, 2I), GregorianDate.DayOfYear.ToString("000")).TrimStart("0"c)
    30.     End Function
    31.  
    32.     Private Function IsJDEDate(ByVal dte As String) As Boolean
    33.         Dim Output As Boolean = False
    34.         dte = dte.Trim
    35.         If dte.Length > 0I AndAlso Long.TryParse(dte, New Long) Then
    36.             Dim DayOfYearStr As String = If(dte.Length > 3I, dte.Substring(dte.Length - 3I, 3I), dte)
    37.             Dim DayOfYearInt As Integer = Integer.Parse(DayOfYearStr)
    38.             If DayOfYearInt >= 0I AndAlso DayOfYearInt <= 366 Then
    39.                 If dte.Length > 3I Then
    40.                     dte = dte.Substring(0I, dte.Length - 3I)
    41.                     Dim YearStr As String = If(dte.Length > 2I, dte.Substring(dte.Length - 2I, 2I), dte)
    42.                     Dim YearInt As Integer = Integer.Parse(YearStr)
    43.                     If YearInt >= 0I Then
    44.                         If dte.Length > 2I Then
    45.                             dte = dte.Substring(0I, dte.Length - 2I)
    46.                             If Integer.Parse(dte) >= 0I Then Output = True
    47.                         Else
    48.                             Output = True
    49.                         End If
    50.                     End If
    51.                 Else
    52.                     Output = True
    53.                 End If
    54.             End If
    55.         End If
    56.         Return Output
    57.     End Function
    58.  
    59. #End Region

    Quote Originally Posted by techgnome View Post
    drop the century digit... take the year, use it to build the date 1/1 for that year... then use the DateAdd (or .AddDays if using .NET) to add the number of days (less 1) to the 1/1 date... that should then return the correct date.

    -tg

    Juggalo - Hold on a moment there.... in your post, you said:
    "For the century I take the 3rd digit in the year and I add 1 to it, so for 2012 I take the 0 and add 1." -- but isn't the third digit "1" ?? 2-0-1-2 ... or did you mean the "second" digit in the year?

    -tg
    Post edited

  7. #7
    New Member
    Join Date
    Jan 2013
    Posts
    3

    Re: [RESOLVED] Converting Gregorian to JDE Julian & back

    thank you very much both of you

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.