Determining age in hours with DateDiff function

M

Mark S

I am trying to calculate how many hours old a baby is if I know the date of
birth and the hour. (Risk for complication of jaundice)

I used =datediff("h",{BirthDate],Now())+ Int(Format(Now(),"mmdd")<Format
([BirthDate],"mmdd")) to see the hours and can set the conditions of risk
with a color change.

If I enter the date - the time is set to12:00 AM so if a baby was born at
6:00 AM it calculates the age is 6 hours more than is true. I need to
indicate the exact date and time and wasn't sure how or if I could do that.
Even if the date is set to general you can't edit the time. THis is as close
to programming as I am competant to do.

How can I add the exact Date and Time to the hour and use the DateDiff
function to calculate the correct hour of age when I open my form?
*****************************************
Mark M Simonian MD FAAP
681 Medical Center Dr West #106
Clovis, CA 93611
(559) 325-6850
www.markmsimonian.medem.com
 
M

Michel Walsh

Hi,


DateDiff returns the number of "change", not the 'real' difference.
Basically, the real difference has to be corrected by "if the hour" is past,
or not.


DateDiff("d", #2-20-2006 18:00:00#, now()) + Int( Hour(#2-20-2006
8:00:00# ) > Hour(now() ) )


returns the complete number of days completed. On the other hand, you can
simplify the expression since, in this case, a days has always 24 hours, so


DateDiff("h", #2-20-2006 18:00:00#, now()) \ 24

returns the number of fully completed periods of 24 hour.

DateDiff("h", #2-20-2006 18:00:00#, now()) MOD 24

return the number of hours done in the incomplete period of 24 hour (well,
more precisely, the number of hour changes; use minutes change, instead of
hour change, for more precisions, if required).


Well, I am wrong in another aspect, that is when light time saving change of
hour occur, twice a year, there is also a problem in the computation... it
will be imprecise by one hour. If you really need to be concerned by that
possibility, see http://www.mvps.org/access/api/api0024.htm which supplies a
"preciseDateDiff" handling that case.



Hoping it may help,
Vanderghast, Access MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top