Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Date/String comparison?

Status
Not open for further replies.

javoine

Programmer
May 22, 2003
25
US
Greets,

I am trying to retrieve a date value stored on another page and compare the value retrieved with another value.

the date is coming from a listbox on page A and being retreived like this:

String eDate = request.getParameter("Dt");
session.setAttribute("endate",eDate);

on page B, i see that it stored the value successfully and will even print the value on the page UNTIL i add the if statement:

String varDate = (String)session.getAttribute("endate");

// out.print(varDate); (this one worked)
if(varDate == "2003-09-08 11:30:00"){ (this didnt)
out.print(varDate);
}

If i remove the quotes "" from the date i get an error, however with them there, it does not seem to read the value properly and will not enter the if.

any suggestions?

thanks in advance.

 
>>>> if (varDate == "2003-09-08 11:30:00)

In Java, the operator "==" compares two objects themselves for equality - it does not compare the VALUE of two objects (like some scripting and shell languages)

Try

if (varDate.equals("2003-09-08 11:30:00")) {
 
Ah! I must forget my old ways...Thank you sedj i really appreciate it.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top