Hi all,
I need help in writing a method that calculates & returns a person's age (in years)given instance variables day, month & year all of type integer(int).
DaniWeb Member Rules include:
"Do provide evidence of having done some work yourself if posting questions from school or work assignments"
http://www.daniweb.com/community/rules
Post what you have done so far and someone will help you from there. Be specific.
Computing date differences is cumbersome, for example, leap years.
I suggest using something where somebody already wrote the function.
Postgres:
1. Install PostgreSQL Click Here;
2. Use PostgreSQL's age() function.
http://www.postgresql.org/docs/9.2/static/functions-datetime.html
This method does have advantages:
A. It works;
B. It takes leap years into account;
C. You get an excellent, stable, tested, easy-to-install database for free.
PHP:
1. Install PHP Click Here;
2. Use PHP's date_diff function;
A. Advantages: you get PHP, which is incredibly cool.
B. http://us3.php.net/manual/en/function.date.php
Ruby:
http://www.tutorialspoint.com/ruby/ruby_date_time.htm
Surprisingly, JavaScript doesn't do this.
Hello stercor
Do you know Java? It has comprehensive data handling classes as part of the every installation. Suggesting installing a database or another language to process dates in the Java forum is just silly. Plus it's obvious that the OP has been set the task of trying to code that functionality for himself.
DaniWeb Member Rules (which you agreed to when you signed up) include:
Do ensure that all posts contain relevant content and substance and are not simply vehicles for external links
Normally a post like yours would get deleted, and repetition would lead to an infraction, but as this is your first post we'll write it off as a learning experience.
I need clarification on "repetition:"
1. repetition of the answer to the same question;
2. repetition of the content of answers to other questions. As an example, I don't know Java; did you comment because of this?
Further:
3. I was not being facetious. I'm 70, and what I don't know about OO would fill volumes.
4. I've written this exact function in S/370 assembler, therefore the leap year comment.
To clarify:
Your post violated the DaniWeb ruleDo ensure that all posts contain relevant content and substance and are not simply vehicles for external links
because your content was irrelevant and just referred to (irrelevant) external links.
Now that you are aware of that, you may be penalised for violating DaniWeb rules in future.
If you don't know Java then it's unlikely that you will have much to contribute in a Java forum. Maybe you could be more at home in the Database or PHP forums?
I apologize for becoming "off topic." But I'm new and don't know where to go for answers.
I didn't see/know that this is a Java forum. Had I seen that I wouldn't have even tried to answer the question.
untio's answer taught me something about Java. Thanks, untio.
I need an answer to my "repetition" question? This is important because it affects my future answers to questions in an appropriate forum.
Is there somewhere I can get clarification of the rules? Perhaps an "answer review" forum for new posters?
OK, don't worry. If you stick to giving relevant answers you are unlikely to get into any trouble. Here's the complete set of Community rules, for future reference. If you have any questions you can PM any Moderator or Administrator.
Anyway, let's just treat this as part of the learning process. You have not been penalised in any way, nor given any "black marks". Your slate is clean. Enjoy DaniWeb.
J.
Thanks untio.
I did have the java.util.Date & java.util.GregorianCalendar pkgs in mind, however in reading the Java API i understood that methods in the Date class were deprecated and that the calendar class should be used instead.
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.