sdesar
asked on
How to compare Dates with Current Date in JSP ?
Hello,
I would like to know how to compare dates with todays date ?
Example In the JSP -
Date today;
String s_date_now;
SimpleDateFormat formatter;
formatter = new SimpleDateFormat("MM/dd/yy yy");
today = new Date();
s_date_now = formatter.format(today);
out.print ( "JavaDate: " + s_date_now);
<td> <span class="label"> </span> <% out.print ( x_crewing.getStartDateOfMe mberInShow (s_email );%> <br> </td>
<td> <span class="label"> </span> <% out.print ( x_crewing.getEndDateOfMemb erInShow(s _email );%> <br> </td>
The output is
Member Start Date EndDate
Sarah 01/10/2006 08/31/2006
Alex 01/10/2006 04/01/2006
My question is how do I modify the above code - so if todays date is within the above date range - then just print "PRESENT" else print the dates as above.
Please advise
Thanks
I would like to know how to compare dates with todays date ?
Example In the JSP -
Date today;
String s_date_now;
SimpleDateFormat formatter;
formatter = new SimpleDateFormat("MM/dd/yy
today = new Date();
s_date_now = formatter.format(today);
out.print ( "JavaDate: " + s_date_now);
<td> <span class="label"> </span> <% out.print ( x_crewing.getStartDateOfMe
<td> <span class="label"> </span> <% out.print ( x_crewing.getEndDateOfMemb
The output is
Member Start Date EndDate
Sarah 01/10/2006 08/31/2006
Alex 01/10/2006 04/01/2006
My question is how do I modify the above code - so if todays date is within the above date range - then just print "PRESENT" else print the dates as above.
Please advise
Thanks
ASKER
Hello ,
Thanks for the prompt reponse!
This is what I tried , but I am getting an error .. please advise
ie if Sarah's End date is after Todays date then I want to print PRESENT , here's the code ..... please advise
<% if ( x_crewing.getEndDateOfMemb erInShow(" Sarah).aft er(s_date_ now) == true ) { out.print ("PRESENT"); } %>
Awaiting a response.
Thanks
Thanks for the prompt reponse!
This is what I tried , but I am getting an error .. please advise
ie if Sarah's End date is after Todays date then I want to print PRESENT , here's the code ..... please advise
<% if ( x_crewing.getEndDateOfMemb
Awaiting a response.
Thanks
ASKER
This is the error -
cannot find symbol
symbol : method after(java.lang.String)
cannot find symbol
symbol : method after(java.lang.String)
it must be.(a double quote is missing).
<% if ( x_crewing.getEndDateOfMemb erInShow(" Sarah").af ter(s_date _now) == true ) { out.print ("PRESENT"); } %>
does x_crewing.getEndDateOfMemb erInShow(" Sarah") returns Date Object ????
Thank You.
<% if ( x_crewing.getEndDateOfMemb
does x_crewing.getEndDateOfMemb
Thank You.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
The x_crewing method returns a String.
I was able to use the above code to get the data.
I will change it to use Calander.
Here are your excellent points.!!
Thanks Fargo.
I was able to use the above code to get the data.
I will change it to use Calander.
Here are your excellent points.!!
Thanks Fargo.
ASKER
If there is no data then I get this error
javax.servlet.ServletExcep tion: Unparseable date: ""
Since x_crewing.getEndDateOfMemb erInShow(s _email )) returns a String and the String is null.
How do i fix this error, I tried to check for null value but its not working.
Please advise.
javax.servlet.ServletExcep
Since x_crewing.getEndDateOfMemb
How do i fix this error, I tried to check for null value but its not working.
Please advise.
ASKER
I figured it out. I needed to check for null. Thanks anyways.
http://www.javaalmanac.com/egs/java.util/CompDates.html