Click here to Skip to main content
15,884,537 members
Please Sign up or sign in to vote.
2.20/5 (3 votes)
See more:
I want to create a uniqueid for the transactions with prefix "yymmdd"(current system date) followed by running numbers starts from 1 that auto increments . For the next day transactions the running numbers should start from 1 with prefix yyMMdd(current system time).





Thanks in advance
Posted
Comments
Pheonyx 11-Jan-16 5:05am    
This question is not likely to get you much help, I would suggest you edit your current statement to include what you've tried/researched and where exactly you have gotten stuck. Things to consider might be .ToString(), Database fields for storing daily increment value etc.
BillWoodruff 11-Jan-16 8:58am    
What you describe does not sound difficult to me, but you need to help us understand the context here. Is this an application running on a server, or, is it a stand-alone Win?WPF/WinForm app. Is it a Win Service ? Is it liked to a database ?

Do you need these identifiers generated on demand (asynch), or on schedule (using timers ?) ?

The use of the word "transactions" suggests this is a server app updating a database.
Philippe Mori 11-Jan-16 12:58pm    
If you have a lot of transaction per seconds from multiple clients, then having an incremental ID might have an impact on performance. Also, it a transaction fails, does it matters if the ID is lost? It is much easier to use unique id generated by the database but it won't restart each day. If it is not an absolute requirement, I would recommand to discard that requirement.

1 solution

You'll have to write all the code to do this as there is no magic built-in function that will already do this for you. But it is very easy to do. You already know you want your date in a certain format so you call .ToString(format) on your date object, DateTime.ToString Method (String) (System)[^].

Then somewhere store the next number to use and concatenate it. Simple. Also, check the time each day and somewhere a flag where this is the first number for the day so you can reset it.
 
Share this answer
 
Comments
BillWoodruff 11-Jan-16 11:33am    
I don't think the OP has provided enough information (yet) to give any meaningful answer.
Philippe Mori 11-Jan-16 12:54pm    
If the code is on a server, you will typically have to somehow handle the case when you get simultaneous request somehow... It make the difference between very easy ans somewhat hard.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900