# Date Diff

**URL:** <https://forums.thehomestack.io/t/date-diff/288>\
**Category:** vb.Net\
**Created:** [December 10, 2007, 4:55pm UTC](https://forums.thehomestack.io/t/date-diff/288 "2007-12-10T16:55:09Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://forums.thehomestack.io/uploads/default/original/1X/161426793bc0d8bdf0d1a6692b3e44446861cc72.jpeg) [@system](https://forums.thehomestack.io/u/system)\
**Post date:** [December 10, 2007, 4:55pm UTC](https://forums.thehomestack.io/t/date-diff/288/1 "2007-12-10T16:55:09Z")

</div>

Here is a code snippet to check the difference in dates:

```auto
Public Function Age(ByVal Birthdate As System.DateTime) As Long
Try
Dim CurrentDate As System.DateTime = System.DateTime.Today
Select Case Month(Birthdate)
    Case Is < Month(System.DateTime.Today)
        Age = DateDiff("YYYY", Birthdate, Now())
    Case Is = Month(CurrentDate)
         Select Case Day(Birthdate)
             Case Is < Day(CurrentDate)
                Age = DateDiff("YYYY", Birthdate, Now())
             Case Is = Day(CurrentDate)
                Age = DateDiff("YYYY", Birthdate, Now())
             Case Is > Day(CurrentDate)
                  Age = DateDiff("YYYY", Birthdate, Now()) - 1
         End Select
    Case Is > Month(CurrentDate)
        Age = DateDiff("YYYY", Birthdate, Now()) - 1
    Case Else
        Age = 0
End Select
Catch ex As System.Exception
    'Error handling code does here
End Try
End Function

```
