Hi,

I have a html table , in table i am displaying dates in column called date, now i want to compare dates in the date column with current system date.
if any one have existing code(in jsp ,javascript) for this please forward me or any advise and suggestions are appriciated.

query 2:

i have two date columns (called startdate, enddate)in my database ,in that i am displaying one column (enddate)in front end in table format .
now the problem is i have to compare these two fields i.e startdate which is in backend and enddate in which i display in fornt end. and perform some calculation. please tell how to compare these two.

using jsp or javscrip t or any other suggestions are appreciated

Regards
Akash

> i want to compare dates in the date column with current system date.
Check the 'before()', 'after()' and 'equals()' methods of the Date or the Calendar class.

> now the problem is i have to compare these two fields
Without knowing the scenario, it would be difficult to suggest anything. Since one of the values is in the database, do the comparison in the servlet itself.

hi

thanks for the reply, i am not able to understand what u have quoted for first query. please give me an example code to compare date column with system date.

Regards
Manjunath

There are a lot many ways of comparing dates depending on the source of dates and which class you are using to represent them (Date, java.sql.Date, Calendar), which would accordingly require some conversion.

Here is a simple example of comparing two java.util.Date objects.

public static void main(String[] args) throws ParseException
{
    Date today = new Date();
    Date before = new SimpleDateFormat("dd/MM/yyyy").parse("26/07/2007");
    if(today.after(before))
    {
        System.out.println("[" + today + "] lies after [" + before + "]");
    }
    else
    {
        System.out.println("[" + today + "] lies before or is the same as [" + before + "]");
    }
}

but of course you shouldn't do any of that in a JSP as it's not what they're meant for.
In JSTL you could just use < and > to compare context fields containing Dates of course.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.