# Thread: number of the days (-) days gone past

1. Member
Join Date
Dec 2011
Posts
16
Rep Power
0

## number of the days (-) days gone past

Hello Folks

On my form I want to display the number of day.. i.e.
Jan 1 is day 1
jan 2 is day 2
Feb 1 is day 32 and december 31 is day 365 or 366 depending on leap year or not

i have used all kind of techniques such as date1 - date2 etc...
but nothing seems to work for me cant get the logic right may be.. what i want is count and add the number of the months that has gone past plus the number days of the running month i. 22nd may 2012 is day number (31(jan)+29(feb)+31(mar)+30(apr)+22(currentdate)) = 145 and they will keep adding plus one every time a day go past... thanks

2. ## Re: number of the days (-) days gone past

Or if this is homework and you have to reinvent the wheel, post your best efforts and indicate where exactly you still have a problem.

db

3. Moderator
Join Date
Apr 2009
Posts
11,302
Rep Power
18

## Re: number of the days (-) days gone past

So what code have you got so far, since you say you have "used all kind of techniques"?

4. Member
Join Date
Dec 2011
Posts
16
Rep Power
0

## Re: number of the days (-) days gone past

its not a homework its real work which i am doin free for someone....

Java Code:
```//constructor
public DateDifference() {
Calendar cal1 = new GregorianCalendar();
Calendar cal2 = new GregorianCalendar();

cal1.getTime();
//System.out.println(cal1);
cal2.set(2012, 01, 01);
//System.out.println(cal2);
//daysBetween(cal1.getTime(), cal2.getTime());
System.out.println("Days= "+ this.daysBetween(cal1.getTime(),cal2.getTime()));
}

public int daysBetween(java.util.Date date, java.util.Date date2){
return (int)( (date2.getTime() - date.getTime()) / (1000 * 60 * 60 * 24));
}```
there are few more which doesnt make sence but i cant manage to get the logic right...

thanks

5. Member
Join Date
Dec 2011
Posts
16
Rep Power
0

## Re: number of the days (-) days gone past

Thankyou very much DarrylBurke i got my answer thanks very much

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•