Re: How to know the date is first,second,third weeks...
Sherm Pendley wrote:
weetat <weetat.yeo@gmail.com> writes:
Our client want us to check if for example the release_date is 9
August 2007 is on the first week of the month. However it did not the
referred to month but to release_date.
Have a look at the java.util.Calendar class. For example:
import java.io.*;
import java.util.Calendar;
public class CalendarExample {
public static void main (String argv[]) {
Calendar cal = Calendar.getInstance();
cal.set(2007, 8, 9); /* year, month, day */
System.out.println("Week of Month: " +
cal.get(Calendar.WEEK_OF_MONTH));
}
}
Another approach, useful if you have to characterize dates more fully as, for
example, weekday vs. weekend, holidays (perhaps with separate logic for
holidays in different countries), "A" days vs. "B" days or other attributes
not known to java.util.Calendar, is to use a database table of dates. Each
date is tagged with the attributes of interest. Then all you have to do is
SELECT from that table to find out if a given date is a weekend, holiday or
whatever. It also supports queries like "how many non-holiday days are in an
interval, after the first four?"
--
Lew