We help IT Professionals succeed at work.

Julian date to a format dd/mm/yyyy

1469
1469 asked
on
Medium Priority
817 Views
Last Modified: 2012-06-21
Hello,
I have a formula to obtain the Julian date that is the follow:

a=(14-month)/12
y = year + 4800 - a
m = month + 12a - 3

JD = day + (153m +23)/5 + 365y + y/4 - 32045

Has anyone used this function before¿?

And now to obtain the function that converts a date julian to string format normal date¿?
Comment
Watch Question

what programming language are you using?  

subtract 2451700 (which is the JD for Jan 1, 2000) from the JD that you want to convert, and then add (or subtract as the case may be) that many days from Jan 1, 2000 to get the date the corresponds to the JD that you have.

AW

Author

Commented:
VB
You have asked this precise question elsewhere (Math & Science), and that violates the EE rule about offering more than 500 points TOTAL for a question.  You have also accepted the answer provided in the other question, so there seems to be very little to be served by offereing an answer here.

To get the Current Date from a give JD, in VB or VBA:

Dim strCurentDate as string
 
strCurrentDate = Format(DateAdd("d", JD - 2451700, #Jan 1, 2000#), "MMM dd, YYYY")
You might be able to get both questions cut down to 250 points each.  I for one am interested in both the programming angle and the historical angle.
Employee in Civil Service
CERTIFIED EXPERT
Commented:
Hi,

This function will return the exact Julian Date for a given vbDate entry:


'The Function:
Public Function JulianDate(ByVal datDate As Date) As Double
    Dim GGG
    Dim DD, MM, YY
    Dim S, A
    Dim JD, J1
    Let MM = Month(datDate)
    Let DD = Day(datDate)
    Let YY = Year(datDate)
    Let GGG = 1
    If (YY <= 1585) Then
        GGG = 0
    End If
    Let JD = -1 * Int(7 * (Int((MM + 9) / 12) + YY) / 4)
    Let S = 1
    If ((MM - 9) < 0) Then
        S = -1
    End If
    Let A = Abs(MM - 9)
    Let J1 = Int(YY + S * Int(A / 7))
    Let J1 = -1 * Int((Int(J1 / 100) + 1) * 3 / 4)
    Let JD = JD + Int(275 * MM / 9) + DD + (GGG * J1)
    Let JD = JD + 1721027 + 2 * GGG + 367 * YY
    If ((DD = 0) And (MM = 0) And (YY = 0)) Then
      MsgBox "Please enter a meaningful date!"
    Else
      Let JulianDate = JD
    End If
    Exit Function
JulianDate_Error:
    MsgBox "MainModule.JulianDate()"
    Exit Function
    Resume
End Function

'How to call the function:
Private Sub Command1_Click()
    MsgBox (JulianDate(Now))
End Sub


To verify the results of the suggested piece of code you might check the generated result using the Julian Date Converter at: http://aa.usno.navy.mil/data/docs/JulianDate.html


PS: I'll post this answer at both channels -> I think it's worth it! ... ;-)
Best regards,
Raisor

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.