[Webinar] Learn how to a build a cloud-first strategyRegister Now


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

Posted on 2008-11-16
Medium Priority
Last Modified: 2012-05-05
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

Question by:mcainc
1 Comment
LVL 14

Accepted Solution

Binuth earned 2000 total points
ID: 22973555
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


Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses

868 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question