Gustav Brock
gustav at cactus.dk
Fri Aug 1 14:29:02 CDT 2003
Hi Bobby > This function can be made even more generic by passing in the month, day, > year, and day fraction (or the day as a fraction 12/4/2003 6:00AM would be > 12, 4.25, 2003). This way, the function can handle years BC. > Just in case anyone cared. :-) Well, could be interesting ... who knows, but it still fails an example like this: ? (Greg2jd("03/01/1992") - Greg2jd("03/01/1987")) / 365.25 4,99931553730322 like any other method relying on dividing by 365,25. This method is what we call a "shoemaker method" as it is a method working in "most cases" but not all. This is not to pick on you - because it is still published many places - but for the records, so no list member should be tempted to use a quick and dirty suggestion for serious use. /gustav > Public Function Greg2JD(ByVal strDate As String) As Double > Dim A As Long > Dim B As Long > Dim MM As Long > Dim YY As Long > Dim DD As Single > MM = Month(strDate) > YY = Year(strDate) > DD = Day(strDate) > 'note, you could pass the time of day in as a fraction of a day. > 'if you do so, simply add the fraction of the day to DD > 'As is, this code assumes 0 hour, i.e. if it is the 4th, > 'then it assumed to be the 4th at 12:00:00 AM > 'DD = DD + sDayFrac 'sDayFrac is the variable holding fraction of day > If MM < 3 Then > YY = YY - 1 > MM = MM + 12 > End If > A = YY \ 100 'integer math > B = 2 - A + A \ 4 'integer math > Greg2JD = Int(365.25 * (YY + 4716)) + Int(30.6001 * (MM + 1)) + DD + B - > 1524.5 > End Function > To work out our example, I called it with: > Debug.Print (Greg2JD("02/18/2002") - Greg2JD("02/29/1988")) / 365.25