471,318 Members | 3,236 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,318 software developers and data experts.

Birthday generated by ID number

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

Dec 14 '05 #1
8 11352
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
"Wolf" <ja********@citadel.co.za> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
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

Dec 14 '05 #2
This is bad design. You should be using two seperate columns (im assuming
this is how IDNumber is stored in the db).

--

Derek Davis
dd******@gmail.com

"Wolf" <ja********@citadel.co.za> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
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

Dec 15 '05 #3
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

Dec 15 '05 #4
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;

Dec 15 '05 #5
This topic would get a tad bit diff response in a more db specific NG. Ask
Joe Celko his opinion on the subject.

http://www.webopedia.com/TERM/K/kludge.html ;)

--

Derek Davis
dd******@gmail.com

"Steven Nagy" <le*********@hotmail.com> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.com...
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

Dec 16 '05 #6
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!

Dec 16 '05 #7
> 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.***

--

Derek Davis
dd******@gmail.com
Dec 16 '05 #8
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

Dec 16 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

51 posts views Thread by Sandra | last post: by
1 post views Thread by Claude Alain | last post: by
2 posts views Thread by David Garamond | last post: by
5 posts views Thread by NomoreSpam4Me | last post: by
kestrel
13 posts views Thread by kestrel | last post: by
1 post views Thread by TWX | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.