1 Replies - 1229 Views - Last Post: 30 March 2012 - 09:44 AM Rate Topic: -----

#1 NessValdez  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 70
  • Joined: 12-March 12

Random date generator

Posted 30 March 2012 - 09:10 AM

Hey! Im doing a project where the computer generate a random date and the user has to guess what day of the week it lands on. I have the random generator but I would like to change it where the month is not a integer . . . For example, March 30, 2012 instead of 3/30/2012. Here is my code so far . . .

Dim Date1 As Date, Date2 As Date
        Date1 = "01/01/1000"
        Date2 = "12/31/9999"

        'number of days between dates
        Dim iDiff = DateDiff("d", Date1, Date2, vbMonday)

        Dim RndDate As Date
        Randomize()
        RndDate = DateAdd("d", Int((iDiff * Rnd()) + 1), Date1)

        Label2.Text = RndDate


Is This A Good Question/Topic? 0
  • +

Replies To: Random date generator

#2 CharlieMay  Icon User is online

  • This space intentionally left blank
  • member icon

Reputation: 1387
  • View blog
  • Posts: 4,467
  • Joined: 25-September 09

Re: Random date generator

Posted 30 March 2012 - 09:44 AM

Look at the Methods for DateTime

There are methods for converting "03/30/2012" to "March 30, 2012"

RndDate.

Will open the intellisense window where you can see properties and methods that will help you with this.

If you don't like any of those options, you also have the ability of formatting it with the .ToString() method to better suit your needs.

This post has been edited by CharlieMay: 30 March 2012 - 09:53 AM

Was This Post Helpful? 1
  • +
  • -

Page 1 of 1