Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / New Users / July 2006

Tip: Looking for answers? Try searching our database.

James D.

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
James D. - 06 Jul 2006 20:46 GMT
Can any one tell me why when I use the datediff function  and specify years,
It gives me a date "3/4/1899"  nstead of a period of time? Is it my date
format?

The two dates are as follows:
daDob 08/04/1946
daPatientAge 9/21/2005

The code is as follows:
daPatientAge = DateDiff("yyyy", daSpecDate, daDOB)

Any suggestions would be great.

Thx.
Douglas J Steele - 06 Jul 2006 21:04 GMT
DateDiff doesn't return a date: it returns a number indicating the number of
years (in this case) between the two dates.

?DateDiff("yyyy", #8/4/1946#, #7/6/2006#)
60

The reason you're get 3/4/1899 is because internally, Access stores dates as
8 byte floating point numbers, where the integer portion represents the date
as the number of days relative to 30 Dec, 1899, and the decimal portion
represents the time as a fraction of day. I have no idea what value you
passed for daSpecDate, but it must have resulted in DateDiff returning -301.

BTW, see http://www.mvps.org/access/datetime/date0001.htm at "The Access
Web" for how to calculate age. DateDiff is a little too literal: it sees the
difference between 12/31/2005 and 1/1/2006 as 1 year.

Signature

Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)

> Can any one tell me why when I use the datediff function  and specify years,
> It gives me a date "3/4/1899"  nstead of a period of time? Is it my date
[quoted text clipped - 10 lines]
>
> Thx.
Klatuu - 06 Jul 2006 21:10 GMT
daPatientAge should be a Long data type, not a date.  DateDiff returns the
number of intervals specified between the two dates.  Since daPatientAge is a
date type, it will turn the value returned by the DateDiff function into a
date.  That is not what you want.

> Can any one tell me why when I use the datediff function  and specify years,
> It gives me a date "3/4/1899"  nstead of a period of time? Is it my date
[quoted text clipped - 10 lines]
>
> Thx.
John Vinson - 06 Jul 2006 21:20 GMT
>Can any one tell me why when I use the datediff function  and specify years,
>It gives me a date "3/4/1899"  nstead of a period of time? Is it my date
[quoted text clipped - 10 lines]
>
>Thx.

daParentAge will NOT be a date/time value - it will be an integer (and
will not give the correct age in years either, see below).

A Date/Time value is stored as a Double Float number, a count of days
and fractions of a day (times) since midnight, December 30, 1899.
Dates before then are stored as negative numbers.

DateDiff returns an INTEGER - not a date; you don't say what
daSpecDate is (today's date??) but your expression will return an
integer number of years by which daDOB is AFTER daSpecDate.

A correct expression for the age as of the previous birthday is

lngPatientAge = DateDiff("yyyy", daDOB, Date()) - IIF(Format(daDOB,
"mmdd") > Format(Date(), "mmdd"), 1, 0)

This will calculate the years and subtract one if the person's
birthday has not yet occurred.

I am not at all sure what you mean by saying that the patient's age
(daPatientAge??) is 9/21/2005.

                 John W. Vinson[MVP]    
James D. - 07 Jul 2006 14:19 GMT
Many Thanks, as you wrote it is the datediff function was returning into a
date data type hence the error.

Thanks again.

> >Can any one tell me why when I use the datediff function  and specify years,
> >It gives me a date "3/4/1899"  nstead of a period of time? Is it my date
[quoted text clipped - 34 lines]
>
>                   John W. Vinson[MVP]    
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.