i 'm getting the date in dateField variable after entering the code for converting the date into Simple Date Format

java.util.Date datefield2 = new java.util.Date(request.getParameter("dateField"));
java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("EEEE,dd MMMM yyyy");
GregorianCalendar startDate = new GregorianCalendar(datefield2.getYear()+1900,datefield2.getMonth(),datefield2.getDay())


String reqdt=sdf.format(startDate.getTime())

i 'm not getting the exact date which i entered in dateField variable when i convert the format instead i'm getting different date

i need to compare the reqdt with the database which contains date's in Simple Date Format

how do i compare it ?

so plz help me in this regard

thank u in advance

I won't claim to know why you are converting this to a GregorianCalendar, but I
will show you two things that you can try. In both these examples the line
from your post for creating "sdf" and "dateField2" should be kept and the line
creating startDate thrown out.

Here the first:
String reqdt = sdf.format(dateField2) ;

Here the second:
GregorianCalendar startDate = new GregorianCalendar( ) ;
startDate.setTime(dateField2) ;
String reqdt = sdf.format(startDate.getTime( ) ) ;

Just check out for the definition of getDay() method...........

public int getDay()......

Returns the day of the week represented by this date. The returned value
(0 = Sunday,
1 = Monday,
2 = Tuesday,
3 = Wednesday,
4 = Thursday,
5 = Friday,
6 = Saturday
)

represents the day of the week that contains or begins with the instant in time represented by this Date object, as interpreted in the local time zone.

Returns:
the day of the week represented by this date.

I think you know your problem now????? its correct actually, beacause its retrning you DAY of a week .... thats why u r getting changed date.....

Nilesh......

In oreder to do it correctly......

use getDate() method instead of getDay();

that will solve your problem................

This way....... it should be...............

GregorianCalendar startDate = new GregorianCalendar(datefield2.getYear()
+1900,datefield2.getMonth(),datefield2.getDate());


Nilesh ...........

This question has already been answered. Start a new discussion instead.