ghost21blade ghost21blade - 1 year ago 84 Question

get birthday from ID card number

i need to extract birthday from Sri Lankan id card.

i tried so hard. See following.

Dim dts as Date = TextBox1.text

TextBox2.Text = dts.DayOfYear

From this code , i can input a day (1992.07.21) to TextBox1 and get output (203) in TextBox2.

BUT this is no i wanted.
I want to input day of year (203) and get output(1992.07.21) .

Thanks in advance.

Answer Source

Here is one quick way of doing it. Knowing a given number of days you can take advantage of built in functions of the system date object. Create a date for the start of a known year and add your days minus one. Then format the results ("MMMM" -> The full name of the month; "dd" -> The day of the month, from 01 through 31). Plus may additional formats.

    Dim NumberOfDays As Integer = 203
    Dim BirthYear As Integer = 1992

    Dim TempDate As New Date(BirthYear, 1, 1)       'January 1, 1992
    TempDate = TempDate.AddDays(NumberOfDays - 1)

    Debug.WriteLine(TempDate.ToString("MMMM dd"))   'July 21 
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download