I just did this with a small method loaded into our Base JSP page (see
following code) and a bit of trickery with the Calendar class in the JSP
(see code below). In our case we needed to get the difference between the
two dates returned as an int. If this isn't self explanatory - please ask
further questions and maybe I will be able to help.
METHOD:
//item Date is a date that comes from our DB as object Date (I believe we
are using Oracle)
public int getAge(Date itemDate)
{
//getTime() converts the date into milliseconds (from the Date class - see
the JavaDoc)
//the division creates a number to the nearest day out of the millesecond
conversion
Long oldDateLong = new Long(itemDate.getTime()/1000/60/60/24);
int oldDate = oldDateLong.intValue();
Date sysDate = new Date();
Long currDateLong = new Long(sysDate.getTime()/1000/60/60/24);
int currDate = currDateLong.intValue();
return currDate - oldDate;
}
JSP TEST PAGE:
<html>
<body>
Item Date: 1/2/2001
<!-- had to use Calendar as some of the Date class methods were deprecated
(see the JavaDoc) -->
<!-- in our "real" app the date will be fed in from a data bag - this was
just a hard coded test -->
<% Calendar Cal = Calendar.getInstance();
Cal.set(Calendar.MONTH, Calendar.FEBRUARY);
Cal.set(Calendar.DATE, 2);
Cal.set(Calendar.YEAR, 2001);
Date itemDate = Cal.getTime();
%>
Age = <%= getAge(itemDate) %>
</body>
</html>
=====================
Hope this helps (versus the pissing contest that seems to be going on
between Michael and Joseph at the moment).
Cheers, Janet
-----Original Message-----
From: ems vasudevan [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, February 06, 2001 8:01 AM
To: [EMAIL PROTECTED]
Subject: comparing date objects
Hi Gurus!
I have to compare two date objects.one is returned
from System.currentimemillisecond. other is a
DateFormat Object retreived from the Database as
string .My Backend is DB2.
Pls help.
Regds with advanced thanks.
__________________________________________________
Do You Yahoo!?
Yahoo! Auctions - Buy the things you want at great prices.
http://auctions.yahoo.com/
===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff
JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST
DIGEST".
Some relevant FAQs on JSP/Servlets can be found at:
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.html
http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets
===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".
Some relevant FAQs on JSP/Servlets can be found at:
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.html
http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets