cancel
Showing results for 
Search instead for 
Did you mean: 

Date comparision in webdynpro java

Former Member
0 Kudos

Hi,

I am new to webdynpro java. I have a requirement. I am getting date in format "yyyymmdd" as string and i need to compare it to todays date.

Please help me how to do this.

Thanks,

Raz

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi,

The way of comparing two date instances is same in WD Java as in plain Java. Assuming you already have got the date value as string from the context, use this code:


String dateStr = "<your value from the context>"; //for example 20071231
		
SimpleDateFormat f1 = new SimpleDateFormat("yyyyMMdd");
		
try {
   Date d1 = f1.parse(dateStr);
   Date d2 = new Date(System.currentTimeMillis()); //today's date
			
   d1.compareTo(d2); // will return -ve if lhs is before rhs, +ve if ihs is after rhs & 0 if both the dates are equal.
} catch (ParseException e) {
   e.printStackTrace();
}

Regards,

Satyajit.

Former Member
0 Kudos

Thanks.. i did on my own.. but it is similar to u only..

thanks a lot..