Unique ID For 30 years

The problem: You need a unique ID for a years worth of records. You could use MM/DD/YY HH:MM:SS SessionID for their uniqueID ... ARE YOU CRAZY ??? This would be fine if you NEVER needed to search the database. Text searches (text/varchar whatever) are the slowest searches of all. But you also can't just use SessionID because they are reused. The real problem with mmddyyhhmmssSessionID is that it is 21 numbers long. Not too many database fields like 21 characters. 18 numbers is the max for big int (actually 2^63, but this isn't a complete 19) SQL bigint and Access decimal 18,0 can both use this function. Numbers are the fastest thing to search, and this function will store up to 30 years staying within that 18 number limit...

The Solution:
Simply use the difference in seconds between the the year 2000 at 12:00:00am, and the second it is right then. Which will stay under 10 digits for 30 years, which will leave the other 9 digits for the 9 digit SessionID if you want to use that too.

The Code:

<% 
Function uid() 
       Dim theseconds 
       theseconds=DateDiff("s", "01/01/2000 12:00:00 AM", Date() & " " & Time()) 
       uid=theseconds 
End Function 

Response.Write uid 
%>

The Result
543848260



asp unique ID session id userid random number unique number


Back To Top
© 1998 - 2017 psacake.com | My3C's

Version 7.2 | Advertise on this site