Gustav Brock
gustav at cactus.dk
Sat Aug 2 04:02:14 CDT 2003
Hi Bobby
I tried to think but I'm not quite sure I can follow you. Only newly
born babies and astrologers care for the time of the day of birth, and
only children are interested in ages with a resolution of months. And,
of course, a new day begins at midnight.
/gustav
> Good point! I did not think that you were picking on me.
> While thinking about this, you technically have to add 0.0001 (may could go
> smaller) day.
> Think about it
> 12/1/99-12/1/99 is technically saying the same as
> 12/1/99 12:00am 0 12/1/99 11:59:59pm, which IMHO is not 1 full day until
> that last second has past (and then it is the next day).
> When you are using my method, I think that maybe you have to add 0.0001 days
> to get the desired results.
> I modified the function to take a fraction of a day and entered .0001 as the
> fraction to add and I get:
> Debug.Print (Greg2JD("03/01/1992",0)-Greg2JD("03/01/1987",0.0001))/365.25=
> 5.00205311425984
> What do you all think?
> Bobby
> -----Original Message-----
> From: accessd-bounces at databaseadvisors.com
> [mailto:accessd-bounces at databaseadvisors.com]On Behalf Of Gustav Brock
> Sent: Friday, August 01, 2003 3:29 PM
> To: Access Developers discussion and problem solving
> Subject: Re: [AccessD] Age calculation function
> 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