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).

6 Years
Discussion Span
Last Post by jockfaire

Computing date differences is cumbersome, for example, leap years.
I suggest using something where somebody already wrote the function.

1. Install PostgreSQL Click Here;
2. Use PostgreSQL's age() function.

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.

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


Surprisingly, JavaScript doesn't do this.

Edited by stercor: More information


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?
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.

Edited by stercor: Clarification


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.


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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.