This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes Java in General and the fly likes How to get yesterday's business date Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "How to get yesterday Watch "How to get yesterday New topic

How to get yesterday's business date

nancy andrew
Ranch Hand

Joined: Jan 19, 2010
Posts: 30
I am writing a program which gets todays date and yesterday's date. The dates should be business dates. If today is Tuesday then it should furnish yesterday's date which was a Monday. But if today is Monday then it should furnish yesterday's date which was a friday. How to write this program in java. Also the dates which i want should be in Eastern standard time. I dont want GMT. Please help me.

Lester Burnham

Joined: Oct 14, 2008
Posts: 1337
Sounds like: create a Calendar object, subtract a day from it, check if it's on a weekend and if so, subtract 1 or 2 days from it depending on whether it's a Saturday or Sunday. The Calendar class has all the methods you'd need for this, and it can handle timezones.

Would you need to consider official holidays as "non-business days"?
Jacob Anawalt
Ranch Hand

Joined: Oct 27, 2010
Posts: 64

If you want something more robust, and especially if you need holidays, consider a library like Objectlab kit. I've been happy with it and Joda.

I agree. Here's the link:
subject: How to get yesterday's business date
It's not a secret anymore!