VB.NET - Getting random date that falls between specific M/D/Y range

I'm trying to make a function that can return a random DOB between a specific Month, Day & Year range

for example

DOB between 5/25/1981 - 4/14/1985

random result could be: 01/22/84
random result could be: 4/13/85

Who is Participating?
BinuthConnect With a Mentor Commented:
try this
        Dim dtOne As New DateTime(2008, 1, 1)
        Dim dtTwo As New DateTime(2008, 1, 31)
        Dim ORandomNumber As New Random()
        Dim iTotalDays As Int16
        iTotalDays = DateDiff(DateInterval.Day, dtOne, dtTwo)
        Dim dtRandomDate As DateTime
        dtRandomDate = dtOne.AddDays(ORandomNumber.Next(iTotalDays))

Open in new window

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.