473,799 Members | 2,935 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to use system time to generate unique id?

I need to generate unique id for my application. Use system time to create
id, which is the best fit, but I don't know how to do it. Please help.

Thanks in advance for any input.
Nov 21 '05 #1
28 17696
What about using the Guid class to generate a new Guid?

"Nina" <Ni**@discussio ns.microsoft.co m> wrote in message
news:36******** *************** ***********@mic rosoft.com...
I need to generate unique id for my application. Use system time to create
id, which is the best fit, but I don't know how to do it. Please help.

Thanks in advance for any input.

Nov 21 '05 #2
GUID is a good way to get a unique id but if you want your id to have some
relationship to the time why not try using the number of days, minutes, or
seconds since the file was created until it was last updated? Actually, I
beleive the applications productBuildPar t information gives you the number
of days since January 1, 2000 to the last day the file was modified?

System.Diagnost ics.FileVersion Info.GetVersion Info( _
System.Reflecti on.Assembly.Get ExecutingAssemb ly.Location).Pr oductBuildPart

If you want the time, in this case using minutes, between when the file was
created to when the file was last modified try -

System.IO.File. GetLastWriteTim e( _
System.Reflecti on.Assembly.Get ExecutingAssemb ly.Location).Su btract( _
System.IO.File. GetCreationTime ( _
System.Reflecti on.Assembly.Get ExecutingAssemb ly.Location)).T otalMinutes

Dave

"Nina" <Ni**@discussio ns.microsoft.co m> wrote in message
news:36******** *************** ***********@mic rosoft.com...
I need to generate unique id for my application. Use system time to create
id, which is the best fit, but I don't know how to do it. Please help.

Thanks in advance for any input.

Nov 21 '05 #3
"Nina" <Ni**@discussio ns.microsoft.co m> schrieb:
I need to generate unique id for my application. Use system time to create
id, which is the best fit, but I don't know how to do it.


The simplest solution is using a GUID:

\\\
Dim ID As String = Guid.NewGuid(). ToString()
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 21 '05 #4
Thank you all for ideas and suggestions. Please tell me how does GUID work?
In case, user exits the application, and lunches the application again later,
could GUID generate same id that was generated in previous session? If this
could happen then I cannot use it.

"Herfried K. Wagner [MVP]" wrote:
"Nina" <Ni**@discussio ns.microsoft.co m> schrieb:
I need to generate unique id for my application. Use system time to create
id, which is the best fit, but I don't know how to do it.


The simplest solution is using a GUID:

\\\
Dim ID As String = Guid.NewGuid(). ToString()
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #5
"Nina" <Ni**@discussio ns.microsoft.co m> schrieb:
Thank you all for ideas and suggestions. Please tell me how does GUID
work?
In case, user exits the application, and lunches the application again
later,
could GUID generate same id that was generated in previous session? If
this
could happen then I cannot use it.


That's very, very, very, ..., very unlikely. In practice it's "guaranteed "
that every GUID only occurs once. There are various parameters used to
calculate the GUID. So you can use a GUID as ID without any fear that
you'll get a GUID twice.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 21 '05 #6
Thanks again. The Id that generated by GUID is very long. Is there any way
that I can generate a unique id with a specific length?

"Herfried K. Wagner [MVP]" wrote:
"Nina" <Ni**@discussio ns.microsoft.co m> schrieb:
Thank you all for ideas and suggestions. Please tell me how does GUID
work?
In case, user exits the application, and lunches the application again
later,
could GUID generate same id that was generated in previous session? If
this
could happen then I cannot use it.


That's very, very, very, ..., very unlikely. In practice it's "guaranteed "
that every GUID only occurs once. There are various parameters used to
calculate the GUID. So you can use a GUID as ID without any fear that
you'll get a GUID twice.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #7
There is nothing stopping you from truncating it.

"Nina" <Ni**@discussio ns.microsoft.co m> wrote in message
news:D2******** *************** ***********@mic rosoft.com...
Thanks again. The Id that generated by GUID is very long. Is there any way that I can generate a unique id with a specific length?

"Herfried K. Wagner [MVP]" wrote:
"Nina" <Ni**@discussio ns.microsoft.co m> schrieb:
Thank you all for ideas and suggestions. Please tell me how does GUID
work?
In case, user exits the application, and lunches the application again
later,
could GUID generate same id that was generated in previous session? If this
could happen then I cannot use it.


That's very, very, very, ..., very unlikely. In practice it's "guaranteed " that every GUID only occurs once. There are various parameters used to
calculate the GUID. So you can use a GUID as ID without any fear that
you'll get a GUID twice.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #8
Thanks. Will truncate causing duplication?

"Marina" wrote:
There is nothing stopping you from truncating it.

"Nina" <Ni**@discussio ns.microsoft.co m> wrote in message
news:D2******** *************** ***********@mic rosoft.com...
Thanks again. The Id that generated by GUID is very long. Is there any

way
that I can generate a unique id with a specific length?

"Herfried K. Wagner [MVP]" wrote:
"Nina" <Ni**@discussio ns.microsoft.co m> schrieb:
> Thank you all for ideas and suggestions. Please tell me how does GUID
> work?
> In case, user exits the application, and lunches the application again
> later,
> could GUID generate same id that was generated in previous session? If > this
> could happen then I cannot use it.

That's very, very, very, ..., very unlikely. In practice it's "guaranteed " that every GUID only occurs once. There are various parameters used to
calculate the GUID. So you can use a GUID as ID without any fear that
you'll get a GUID twice.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>


Nov 21 '05 #9
If you truncated it, wouldn't that introduce the possiblity (albeit slight)
of non-uniqueness?

What if you didn't pass it around as a string, but kept it in its native
datatype? It is only 16 bytes in SQL server when stored as uniqueidentifie r
datatype. Versus the ~36 bytes for the equivalent string.

Greg

"Marina" <so*****@nospam .com> wrote in message
news:Oa******** ******@tk2msftn gp13.phx.gbl...
There is nothing stopping you from truncating it.

"Nina" <Ni**@discussio ns.microsoft.co m> wrote in message
news:D2******** *************** ***********@mic rosoft.com...
Thanks again. The Id that generated by GUID is very long. Is there any

way
that I can generate a unique id with a specific length?

"Herfried K. Wagner [MVP]" wrote:
> "Nina" <Ni**@discussio ns.microsoft.co m> schrieb:
> > Thank you all for ideas and suggestions. Please tell me how does
> > GUID
> > work?
> > In case, user exits the application, and lunches the application
> > again
> > later,
> > could GUID generate same id that was generated in previous session? If > > this
> > could happen then I cannot use it.
>
> That's very, very, very, ..., very unlikely. In practice it's "guaranteed " > that every GUID only occurs once. There are various parameters used to
> calculate the GUID. So you can use a GUID as ID without any fear that
> you'll get a GUID twice.
>
> --
> M S Herfried K. Wagner
> M V P <URL:http://dotnet.mvps.org/>
> V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
>
>
>


Nov 21 '05 #10

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

Similar topics

2
3234
by: Mullin | last post by:
I need to generate a unique no. in the format like yyyymmddxxxxxx (xxxxxx 6-digitl running number) I think of create a table with two columns date value 20050405 120 20050406 99 Everytime, the application will increase the value+1 based on the same
10
18621
by: Mamuninfo | last post by:
Hello, Have any function in the DB2 database that can generate unique id for each string like oracle, mysql,sybase,sqlserver database. In mysql:- select md5(concat_ws("Row name")) from tablename; Here this function generate unique id for each row of the table. Regards..
1
11269
by: hikums | last post by:
I am posting this here, just in case anyone may need this. Step 1: CREATE SEQUENCE ID_SEQ START WITH 1050000 INCREMENT BY 1 MAXVALUE 9999999 NO CYCLE NO CACHE ORDER
11
16229
by: Kovan Akrei | last post by:
Hi, I wonder if there are any others ways (mehtods, properties) to get the system time than DateTime.Now.Ticks Regards from Kovan __________________________________________________________________ R u kidding me Ya right ICQ#: 149146797 Current ICQ status: + More ways to contact me __________________________________________________________________
3
1587
by: palani12kumar | last post by:
i want to generate a random number by using the system time. i dont know how to do it. And another thing is, how to find the millisecond? please help me
15
37600
by: Ashish Khandelwal | last post by:
As MSDN is not giving us guarantee upon uniqueness of Hash Code, so could any one suggest me that how to generate a unique Hash Code for same string always, and generate different-2 Hash Code Different-2 string.
4
2847
by: gaurav1983 | last post by:
i have to generate unique combinations of given number of digits entered by user eg: N=4 (0,1,2,3) output should be 0 1 2 3
1
2750
by: situ | last post by:
Hi, I'm using DB2 V9 for windows I'm inserting records into DGTT from select statement; the problem is how to insert unique value for every row inserted. I tried using “generated always as” clause but its exhausting at some point of time. Say if 100000 records were needed to be processed, it’s only processing up to 60000 rows.
6
2035
by: er | last post by:
hi, here's why i'm trying to do: header1.hpp namespace{ struct A{};} struct B1{ A a; }; header2.hpp namespace{ struct A{};}
0
9688
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9544
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10259
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10238
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9077
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7570
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5467
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5589
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4145
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.