W3C home > Mailing lists > Public > www-forms@w3.org > April 2004

Re: date calculations

From: Jeff <jeff@cogentlogic.com>
Date: Wed, 7 Apr 2004 00:56:16 -0400
Message-ID: <003301c41c5c$a8b57610$0c00000a@thesiger>
To: "Robert Bateman" <bobbateman@sequoiallc.com>, <www-forms@w3.org>

Hi Bob,

For five vanilla days:

    java.util.Calendar calNowPlusFive = java.util.Calendar.getInstance();
    calNowPlusFive.add(Calendar.DATE, 5);
    java.text.SimpleDateFormat sdfISO8601 = new
java.text.SimpleDateFormat("yyyy-MM-dd");
    String strISO8601NowPlusFive =
sdfISO8601.format(calNowPlusFive.getTime());
    // populate xsd:date with strISO8601NowPlusFive


For five business days:


    java.util.Calendar calNowPlusFive = java.util.Calendar.getInstance();
    int nIncrementForFiveBusinessDays = 5;
    int nDayOfWeek = calNowPlusFive.get(Calendar.DAY_OF_WEEK);
    if (nDayOfWeek == Calendar.MONDAY)
        nIncrementForFiveBusinessDays = 7;          // Monday + 5  =>
Saturday so add 2 to bump past weekend
    else if (nDayOfWeek == Calendar.TUESDAY)
        nIncrementForFiveBusinessDays = 6;          // Tuesday + 5  =>
Sunday so add 1 to bump past weekend
    calNowPlusFive.add(Calendar.DATE, nIncrementForFiveBusinessDays);
    java.text.SimpleDateFormat sdfISO8601 = new
java.text.SimpleDateFormat("yyyy-MM-dd");
    String strISO8601NowPlusFive =
sdfISO8601.format(calNowPlusFive.getTime());
    // populate xsd:date with strISO8601NowPlusFive



Jeff
Cogent Logic



----- Original Message ----- 
From: "Robert Bateman" <bobbateman@sequoiallc.com>
To: <www-forms@w3.org>
Sent: Tuesday, April 06, 2004 12:20 PM
Subject: date calculations



I've looked thru as many of the examples from around the web as I can find
and
don't see an obvious way to do date calculations.

What I'm trying to do is populate an xsd:date field with now() plus 5 days
as
it's default value.  The field in question is a proposed "due date" for a
work order.

I've seen that I can get a "difference" between two dates, but no
calculations.


Thanks Much!

Bob
Received on Wednesday, 7 April 2004 01:02:52 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Saturday, 10 March 2012 06:21:57 GMT