cancel
Showing results for 
Search instead for 
Did you mean: 

convert string to date

0 Kudos

Hi All

How can i convert string to date. The r/3 is returning date as string but when i want to display it in portal i need the calendar logo so the date can be changed how can i convert this string to date.

Thanks in advance

Accepted Solutions (0)

Answers (3)

Answers (3)

former_member191569
Active Participant
0 Kudos

Maybe you can change the output data type of your RFC to date.

If not, you have to get the value of the RFC in a string bult-in type context attribute and code manually a conversion from String to Date. Then store the Date value converted to other context attribute and map it to tour InputField UI.

former_member40425
Contributor
0 Kudos

Use following code.

import java.util.*;
import java.text.*;

String str_date="11-June-07";
         DateFormat formatter ; 
     Date date ; 
          formatter = new SimpleDateFormat("dd-MMM-yy"); " Here give the format in which you want your output.
              date = (Date)formatter.parse(str_date);

I hope it helps.

Regards,

Rohit

0 Kudos

Hi Rohit,

I am getting the following error: ava.lang.ClassCastException.

Regards,

Santosh

Former Member
0 Kudos

Hi,

The reason you are getting classCastException is due to invalid date type. The RFC will return or accept java.sql.Date type as Date, since you are using Rohit's code above you are converting to java.util.Date type. So to avoid classCastException, use the below code which is corrected version of Rohit's code

String str_date="11-June-07";

DateFormat formatter ;

formatter = new SimpleDateFormat("dd-MMM-yy"); // Here give the format in which you want your output.

java.util.Date utilDate = (java.util.Date)formatter.parse(str_date);

java.sql.Date sqlDate = new java.sql.Date(utilDate.getTime());

Above code should work and hope it helps.

NOTE: When working with RFC FM's Dates are handled as java.sql.Date in Java not java.util.Date which is default namespace available in all Java classes.

Praveen

Former Member
0 Kudos

Hi,

use the SimpledateFormat class to parse the date.

SimpleDateFormat sdf=new SimpleDateFormat("dd.MM.yyyy");

Date dte=sdf.parse(dateString);

Regards,

Naga