File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes Java Calendar Dates Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Reply locked New topic

Java Calendar Dates

Anil Karamchandan
Ranch Hand

Joined: Sep 12, 2009
Posts: 47
Hi all,

I am currently building a payroll software code and stuck at a point, I would do my best to explain and get any help

I have a pay period Start date and End Date this can be any period

When I enter the period as (in mm/dd/yyyy format)

Start date "04/08/2010"
End Date "05/08/2010"

then I add 1 month to a calendar handler.add(Calendar.Month,1)

the next and the corresponding dates are

Start date "05/08/2010"
End Date "06/08/2010"

Start date "06/08/2010"
End Date "07/08/2010"

corresponding as desired. But the moment I enter the start date and end date as

Start date "04/01/2010"
End Date "04/30/2010" which is a 1 Month period and then add 1 Month to the code
the corresponding dates are

Start date "05/01/2010"
End Date "05/30/2010"

Start date "06/01/2010"
End Date "06/30/2010" [ Even though it has 31 days in June, then from Feb 2011 its like

Start date 01/01/2011
End Date 01/30/2011

Start date 02/01/2011
End date 02/28/2011

Start date 03/01/2011
Start date 03/28/2011

everything ends on the 28th

Can any one let me know why in my first condition the 31st day was being taken care of and in the next condition I am not getting the same output.

Details 04/01/2011 04/28/2011

Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63852

Please do not cross-post the same question in multiple forums. It wastes people's time when multiple redundant conversations take place. Please read this for more information.

[Asking smart questions] [About Bear] [Books by Bear]
I agree. Here's the link:
subject: Java Calendar Dates
It's not a secret anymore!