Help with Generating Random ID

C

Chris

Hi,
I need to generate IDs for entries and I would Like to have it in the
format

MMDDYYYHHMMTTMS-RANDOM NUMBER

I am using the following to generate the random number

Threading.Thread.Sleep(1)
Dim rnd As New Random((CInt(DateTime.Now.Millisecond)))
GenerateTransactionID = rnd.Next().ToString()
Return GenerateTransactionID

How can I get the datetime in the format MMDDYYYHHMMTTMS?

Thanks
 
S

Siva M

Assuming MS is millisecond, try this:

DateTime dt = DateTime.Now;
String rnd = dt.ToString ("MMddyyyyHHmmtt") + dt.Millisecond.ToString());

Note that the millisecond part may have one, two or three digits based on
its value.

Hi,
I need to generate IDs for entries and I would Like to have it in the
format

MMDDYYYHHMMTTMS-RANDOM NUMBER

I am using the following to generate the random number

Threading.Thread.Sleep(1)
Dim rnd As New Random((CInt(DateTime.Now.Millisecond)))
GenerateTransactionID = rnd.Next().ToString()
Return GenerateTransactionID

How can I get the datetime in the format MMDDYYYHHMMTTMS?

Thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top