Im trying to write a short data base to figure age diffence in new borns from their projected date of birth to their actual date of birth. I need the answer to be in weeks and days. Thanks in advance for any help.
Age difference in access 2007
Collapse
X
-
I wrote you some code which will calculate the difference and give the result as a string.
Output looks like:Code:Public Function AgeDiff(dt_ActualBirth As Date, dt_ProjectedBirth As Date) As String 'Code by TheSmileyOne 'Calculates the difference between two input dates, and returns the answer as a string 'Init variables Dim intDays As Integer Dim intWeeks As Integer Dim bPremature As Boolean 'Get total number of days intDays = DateDiff("d", dt_ProjectedBirth, dt_ActualBirth) 'Is baby premature? bPremature = (intDays < 0) 'Get number of weeks intWeeks = Int(Abs(intDays) / 7) 'Get number of remaining days intDays = Abs(intDays) - intWeeks * 7 AgeDiff = intWeeks & " weeks and " & intDays & " days" 'Return result If bPremature Then AgeDiff = AgeDiff & " early" Else AgeDiff = AgeDiff & " late" End If End Function
Code:2 weeks and 0 days late 1 weeks and 3 days early
Comment
Comment