Birthday generated by ID number

  • Thread starter Thread starter Wolf
  • Start date Start date
W

Wolf

Hi

I want to split a IDNumber to determine the date of birth.Something
like this.

DateTime dtBirth

split txtIdNumber in yy mm dd
Assume the idnumber = 8210195017089

dtBirth.NewDate(82, 10, 19)

txtBirthdate.text = dtBirth

Can anyone help me please

Thanks in Advance
 
Hello

you can do something like this

string s = "8210195017089";
MessageBox.Show( s.Substring(0,6));

or

long ln = 8210195017089;
MessageBox.Show(ln.ToString().Substring(0,6));


Regards
Karthik K
 
This is bad design. You should be using two seperate columns (im assuming
this is how IDNumber is stored in the db).
 
I wouldn't be pouncing on the fact that it is a bad design without
knowing the whole reason for it existing in the first place.
I think we should just try to answer the main question here. The
following code is similar to what Karthik was saying:

long ID = 8210195017089;

int year = Convert.ToInt32(ID.ToString(0, 2));
int month = Convert.ToInt32(ID.ToString(2, 2));
int day = Convert.ToInt32(ID.ToString(4, 2));

DateTime dob = new DateTime(year, month, day);

txtBirthdate.Text = dob.ToLongDateString();



Steven Nagy
 
Thank you guys for youre help.I got it right in the meantime.
This was my solution and thanks for confirming it to me

string strIDnumber = txtIDNumber.Text;
int intYear = Convert.ToInt32("19" + strIDnumber.Substring(0,2));
int intMonth = Convert.ToInt32(strIDnumber.Substring(2,2));
int intDay = Convert.ToInt32(strIDnumber.Substring(4,2));
DateTime dtBirthDateFromID = new DateTime(intYear, intMonth,
intDay);
dtBirthDate.Date = dtBirthDateFromID;
 
I don't really see how a DB NG is relevant personally. It was a C#
coding question about how to convert an int into a date time.

The why of it is really up to the programmer. I mean, I totally agree
with you about the DB key thing... I personally would use an identity
and have the dob in a different field.
But thats not really what the person was asking. In fact, in their
initial question there was no mention of a database at all.
And even it there was, perhaps the person doesn't have a choice because
its a legacy application and that's how the data is stored.
In fact, perhaps the context is that they were trying to UPDATE the
database and move the IDnumbers into the date of birth column!
We just don't know, so I personally think we should spend more of our
efforts trying to answer the persons question, rather than restructure
their way of thinking.

Its all good. We all are eternally bound together by our decision to
use C# and that makes us all comrades to the end!
 
I don't really see how a DB NG is relevant personally. It was a C#
coding question about how to convert an int into a date time.

Yes, the OP asked a c# question but the real issue could be in the db. So
many coders have just enough db knowledge to be dangerous!
And even it there was, perhaps the person doesn't have a choice because
its a legacy application and that's how the data is stored.
In fact, perhaps the context is that they were trying to UPDATE the
database and move the IDnumbers into the date of birth column!
We just don't know, so I personally think we should spend more of our
efforts trying to answer the persons question, rather than restructure
their way of thinking.

I suspect the OP is relatively in-experienced. As you stated, there are
many aspects of the OP's situation that we don't know. If I my assumptions
and suspicions are correct, wouldn't you agree that it is better to correct
his implementation now rather than later? What if the OP was/is still in
the early stages of implementation and simply didn't/doesn't know any
better?

***OP please note that this post is not meant to be derogatory in any way.
If I completely missed the mark, I do apologize.***
 
I completely understand where you are coming from in terms of "catching
the problem in its early stages".
But if the OP is indeed inexperienced to the point where they are
creating ID fields in a DB that is a construct of a DOB, then I would
also guess that its not a huge project.
If it IS, then they are going to be caught out anyway with other DB
programming problems and the DOB-ID will be the least of their worries.

Its not unusual to see this kind of DB structure in older applications.

However my guess as to the OP's position is that they are a student
trying to solve some problem or assignment.
Perhaps its even a MCP exam question!

No offense taken here. I just know what its like to ask a question, and
have people try anticipate why I'm doing something as opposed to
actually answering the question.
Usually its so left field its impossible to describe anyway!

Steven Nagy
 
Back
Top