How To Number Of Days In A Given Range-need help

V

vidya

Hi,

I am having 2 date fields. fromDate and toDate. And I want to find out
the number of days that comes under this range. For this,
I am using java.util.GregorianCalendar().

I am adding the code also..

java.util.Calendar dat1 = new java.util.GregorianCalendar();
dat1.clear();
dat1.set(year,month,date);
dat1.complete();

But this is not working. The error is like no matching method is found
for complete();

I thought that i will get the value of the constant variable
DAY_OF_YEAR and use it, but how do we set the value of that variable?

I am crating a new calendar object and with year month and date. Isn't
that enough?

Any help is appreciated.

Regards,
Vidya
 
B

Bryce

Hi,

I am having 2 date fields. fromDate and toDate. And I want to find out
the number of days that comes under this range. For this,
I am using java.util.GregorianCalendar().
See:
http://www.javaalmanac.com/egs/java.util/CompDates.html


I am adding the code also..

java.util.Calendar dat1 = new java.util.GregorianCalendar();
dat1.clear();
dat1.set(year,month,date);
dat1.complete();

But this is not working. The error is like no matching method is found
for complete();

Not sure, whave version of the JDK are you running?
I thought that i will get the value of the constant variable
DAY_OF_YEAR and use it, but how do we set the value of that variable?

set(DAY_OF_YEAR, xxx);
I am crating a new calendar object and with year month and date. Isn't
that enough?

enough for what?
 
R

Roedy Green

I am having 2 date fields. fromDate and toDate. And I want to find out
the number of days that comes under this range. For this,
I am using java.util.GregorianCalendar().

It is a trivial problem with BigDate. Just subtract the two ordinals.
see http://mindprod.com/products1.html#BIGDATE

With calendar, you have to pick a time and a timezone to get rid of
the time components. Then get the long timestamp. Then divide by the
number of milliseconds in a day to get a day ordinal number since
1970-01-01 on each date, then subtract.

See http://mindprod.com/jgloss/calendar.html

for the various ways of computing how long to Christmas.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top