i just dont know how to convert this.

i have three integers for month, date and year. year is a two digit input.

i want to convert these three into one variable type long.. but i dont know how to do it.

i tried adding the three integers, but i get weird results.

i want to do this because i want to compare user input date into the current date. [actually, it's an age calculator.]

waah, help would be greatly appreciated.

You should use the GregorianCalendar class, which implements the Calendar methods, which include setting a date from yy,mm,dd, comparing dates etc.

i'll research about that. thanks.

but is it possible to do this without using that class?

... is it possible to do this without using that class?

Yes, in fact you can code it in binary machine code if you want. But why? Someone has gone to a great deal of trouble to write and test a class that does exactly what you want - why re-invent the wheel?
IMHO a good Java programmer isn't just soneone who knows the language, it'ssomeone who knows and uses the API.

hmm what method in the gregoriancalendar class should i use to compare user input date with the current date?

You can get a Calendar instance set to the current date/time with
public static Calendar getInstance()
You can compare two instances with
public int compareTo(Calendar anotherCalendar)

nb: most of the methods you need are defined in the Calendar abstract superclass, not in GregorianCalendar

i can't get the comparison to work.

birthDate.set(yyyy, mm, dd);

        age = currentDate.get(Calendar.YEAR) - birthDate.get(Calendar.YEAR);

        if(currentDate.compareTo(new GregorianCalendar(currentDate.get(Calendar.YEAR),
                                                    birthDate.get(Calendar.MONTH),
                                                    birthDate.get(Calendar.DAY_OF_MONTH))) < 0) {
            age--;
        }

for example, if i enter 1-22-1991, this returns 18.
if i enter 9-23-1991, this returns 17.
BUT if i enter 8-10-1991, this returns 17!
ALSO if i enter 8-9-1991, this returns 17!

i just can't fugure out what's wrong.
help.

This article has been dead for over six months. Start a new discussion instead.