Age difference in access 2007

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • starspop
    New Member
    • Aug 2010
    • 2

    #1

    Age difference in access 2007

    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.
  • mwasif
    Recognized Expert Contributor
    • Jul 2006
    • 802

    #2
    Moved to MS Access forum.

    Comment

    • TheSmileyCoder
      Recognized Expert Moderator Top Contributor
      • Dec 2009
      • 2322

      #3
      I wrote you some code which will calculate the difference and give the result as a string.

      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
      Output looks like:
      Code:
      2 weeks and 0 days late
      1 weeks and 3 days early

      Comment

      • starspop
        New Member
        • Aug 2010
        • 2

        #4
        Thanks SmileyOne.

        Comment

        Working...