DateDiff Incorrect

Results 1 to 2 of 2

Thread: DateDiff Incorrect

  1. #1
    Join Date
    Dec 1969

    Default DateDiff Incorrect

    I have trying to find the difference between two dates, "10/4/99" and "5/1/01". When I use DateDiff("YYYY","10/4/99","5/1/01") it returns 2. I need to know the actual number of years such as 1.6 instead of just 2001 - 1999 = 2 years. I have used other methods such as (5/1/2001 - 10/4/99) / 365.25 to find the number of years in decimal, but the leap years cause this method to be slightly off. What is a good way to do this to account for leap years?

  2. #2
    Heaven's Martini Guest

    Default this behavior is by design..

    This is an age calculator<BR><BR>but it applies to what you have.<BR><BR>(sql author:Rob Volk,<BR><BR>Sub PrintAge(id)<BR><BR>dim objqrysql2,objqry2<BR><BR> objqrysql2 = "Select DateDIFF(yy,DOB,getDate())-CASE WHEN getDate()&#062;=DateAdd(yy,DateDIFF(yy,dob,getDate ()), DOB) THEN 0 ELSE 1 END AS rAge from table where id = "& id &""<BR><BR> Call CreateRecordset(objqry2)<BR> Call OpenRecordset(objqry2,objqrysql2)<BR> if objqry2.bof and objqry2.eof then<BR> <BR> else<BR> <BR> response.write objqry2("rAge")<BR> end if &#039; end of if qry is empty<BR> Call DestroyRecordset(objqry2)<BR><BR>End Sub

Posting Permissions

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