Click here to Skip to main content
15,922,325 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
I have this function that calculates Julian day:
VB
'The date is June 11 2015
        Dim y As Integer = Now.Year
        Dim m As Integer = Now.Month
        Dim d As Integer = Now.Day

        If m <= 2 Then
            y -= 1
            m += 12
        End If
        Dim A As Double = CDbl(Math.Floor(y / 100.0))
        Dim B As Double = 2 - A + Math.Floor(A / 4)

        Dim JD As Double = Math.Floor(365.25 * (y + 4716)) + Math.Floor(30.6001 * (m + 1)) + d + B - 1524.5

The output of this function is "2457184.5".
And I have this equation which also calculates Julian day:
VB
Dim JD As Double = ((367 * y) - (CInt((7 / 4) * (y + Int((m + 9) / 12)))) + CInt(275 * (m / 9)) + d - 730531.5)

But the output of this equation is "5639.5"
My question is which one is right and which one is wrong and why?
Thanks in advance.
Posted
Updated 11-Jun-15 6:19am
v2
Comments
[no name] 11-Jun-15 12:26pm    
AFAIK, neither is correct. Last time I checked Julian dates cannot be greater than the number of days in the year.
CHill60 11-Jun-15 12:34pm    
Is this a case of Julian calendar versus Julian dates ... Julian dates count the number of days since a particular date ... can't remember which one at the moment... whereas the Julian Calendar is the one (currently?) used in most countries in the world.
Darn - I'm off to google that now :)
al3abby 11-Jun-15 12:46pm    
You're right, I need to calculate the equation of time which depends on the Julian day which is a count of days since Jan 1 4713 BC

Please see the comment by Wes Aday.

First of all, you can use this class: https://msdn.microsoft.com/en-us/library/system.globalization.juliancalendar%28v=vs.110%29.aspx[^].

Here is where you can find right recipe: http://en.wikipedia.org/wiki/Julian_day[^].

I think following it should be trivial. You can check up your results, for example, here: http://www.nr.com/julian.html[^].

—SA
 
Share this answer
 
Comments
CPallini 11-Jun-15 12:39pm    
5.
Sergey Alexandrovich Kryukov 11-Jun-15 12:56pm    
Thank you, Carlo.
—SA
There is always confusion between a Julian Day[^]
Quote:
the continuous count of days since the beginning of the Julian Period
and the Julian Calendar[^] which is essentially a civil calendar which represents dates as year, month, day. For the latter purpose you can use the System.Globalization.JulianCalendar class but not the former. Brittanica gives a nice terse explanation of Julian Period[^]

The Wikipedia link given in Solution 1 and repeated above gives the correct calculation method for a Julian Day. There is a C# representation of that calculation presented on this post[^], however the first of your methods appears to be reasonably accurate.

For testing I prefer the US Naval Observatory website[^] as it caters for a Julian Day beginning at mid-day (i.e. correctly displays the decimal part based on time of day)

Your second method is calculating a quasi-julian day (note the lower case) based on number of days since 01-Jan-2000, which is common enough use in some application areas, for example where there are constraints on variable size. It would not be an appropriate method to use for (for example) Astronomy or Financial services (especially Pensions). The last time I used that approach was on a Dairy Management system on CP/M back in the early 80's where (apart from limited memory) our constraint was the birth year of the oldest known dairy cow in the world!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900