none
[Ask] How to create auto id number using date and yearly format

    Question

  • Dear All,

    I want create auto id number using date and year format, that if changing year, then auto id number will be automatic reset. example case :

    ID Number : "999/12/2013" if year is change, then ID Number : "001/01/2014"

    Please help me for sample code about that.

    Thanks all.

    Monday, June 10, 2013 7:07 AM

Answers

  • Make use of Date Time class functions.

    try this code of lines and let me know.

     private string GetId(string currentId)
            {
                if (!string.IsNullOrEmpty(currentId))
                {
                    var yearFromCurrentId = Convert.ToInt32(currentId.Split('/')[2]);
                    var countFromCurrentId = Convert.ToInt32(currentId.Split('/')[0]);
    
                    if (yearFromCurrentId.Equals(DateTime.Now.Year))
                        return ++countFromCurrentId + "/" + DateTime.Now.Month + "/" + DateTime.Now.Year;
                    else
                        return 0 + "/" + DateTime.Now.Month + "/" + DateTime.Now.Year;
                }
                else
                    return 0 + "/" + DateTime.Now.Month + "/" + DateTime.Now.Year;
            }



    you have to pass the current unique id to generate next id


    Thanks & Regards
    Syed Amjad Sr. Silverlight/WPF Developer,
    yahoo : syedamjad6736@yahoo.com, skype : syedamjad.0786.
    Please use Marked as Answer if my post solved your problem and use Vote As Helpful if a post was useful.

    Monday, June 10, 2013 8:33 AM