473,378 Members | 1,395 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Help with Generating Random ID

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

Sep 27 '05 #1
2 1169
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.

"Chris" <de*****@gmail.com> wrote in message
news:11**********************@g47g2000cwa.googlegr oups.com...
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
Sep 27 '05 #2

There some overloads on the the "ToString" function, one allows you to
format the DateTime string...so it would be

dt.ToString(string format)...

try that...
--
rviray
------------------------------------------------------------------------
rviray's Profile: http://www.msusenet.com/member.php?userid=4211
View this thread: http://www.msusenet.com/t-1871083648

Sep 27 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: eric.gagnon | last post by:
In a program randomly generating 10 000 000 alphanumeric codes of 16 characters in length (Ex.: "ZAZAZAZAZAZAZ156"), what would be an efficient way to ensure that I do not generate duplicates? ...
1
by: Intaek LIM | last post by:
generally, we use srand(time(0)) to generate random numbers. i know why we use time(0), but i can not explain how it operates. first, see example source below. ...
5
by: Buchwald | last post by:
hello group, I have a long (large) script that shows a random picture when a webpage is refreshed. It's long because i have a lot of pictures: 246 Here is some code:...
2
by: Simon Wittber | last post by:
I'm building a web application using sqlalchemy in my db layer. Some of the tables require single integer primary keys which might be exposed in some parts of the web interface. If users can...
1
by: Velhari | last post by:
Hi, I am a beginner. Please tell me, For generating Random Numbers, Initially why we are going for seed method. And another question is that, I want to print unique random number how to print by...
0
by: gunimpi | last post by:
http://www.vbforums.com/showthread.php?p=2745431#post2745431 ******************************************************** VB6 OR VBA & Webbrowser DOM Tiny $50 Mini Project Programmer help wanted...
6
by: Mike Langworthy | last post by:
i can not seem to get this code to work. someone please help using System; using System.Collections.Generic; using System.Text; namespace ConsoleApplication1 { class Program {
0
SammyB
by: SammyB | last post by:
These are some "random" thoughts about generating random numbers in Visual Basic. Wikipedia will give a better introduction than I, see http://en.wikipedia.org/wiki/Random_number_generator. ...
1
by: powerej | last post by:
program is suppose to ask for an input from 1-8, if the user enters a number outside of this range than it will continue to ask until it does, something is wrong and i cant seem to figure it out, i...
26
by: bilgekhan | last post by:
What is the correct method for generating 2 independent random numbers? They will be compared whether they are equal. What about this method: srand(time(0)); int r1 = rand(); srand(rand());...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.