cancel
Showing results for 
Search instead for 
Did you mean: 

Convert date from DD-MM-YYYY to DDMMYYYY.

arjun_thakur
Active Contributor
0 Kudos

Hi Experts,

In my component I am getting a date value from back end in DD-MM-YYYY format. Now I need to pass this date to a bapi but it should be a date value of DDMMYYYY format. Now to convert the fomat I am using the following code.:


DateFormat format=null ; 
Date date=null ; 
format = new SimpleDateFormat("ddmmyyyy");
date = (Date)format.parse(flightdate2); 
"flightdate2 is a string variable which contain date value in DDMMYYYY fromat.

By using this code I am getting a run time error: java.lang.ClassCastException.

I am using date of java.sql.date type. Kindly help me to solve this problem.

Regards

Arjun

Accepted Solutions (0)

Answers (3)

Answers (3)

Former Member
0 Kudos

Hi

You can try the following piece of code :

String convdate = "";
		*String str = "26-05-2009";*
*		String dtformat = "dd-MM-yyyy";*
*		SimpleDateFormat sdf = new SimpleDateFormat(dtformat);*
*		try{*
*			*
*			Date dt = sdf.parse(str);*
*			SimpleDateFormat sdf2 = new SimpleDateFormat("ddMMyyyy");*
*			convdate = sdf2.format(dt);*
*		}catch(Exception e){}*
		

Hope this will help

Thanks

Ritushree

srinivas_sistu
Active Contributor
0 Kudos

Hi,

first thing is

format = new SimpleDateFormat("ddmmyyyy");

replace it with

format = new SimpleDateFormat("ddMMyyyy"); and parse requires a string value

so try this below way

java.util.Date d=null;

d=new SimpleDateFormat("yyyy/MM/dd").parse(strDate);

java.sql.Date dt=new Date(d.getTime()); // if you need a SQL date...

Regards,

SrinivaS

arjun_thakur
Active Contributor
0 Kudos

Hi SrinivaS,

Thanks for your reply. I used the code provided by you but still I am getting the date in the in yyyy-mm-dd format but I want it to be in ddmmyyyy. Please help.

Regards

Arjun

Former Member
0 Kudos

For a clarification,

why do u need the SQL date in the format ddMMyyyy.

AM

arjun_thakur
Active Contributor
0 Kudos

Hi Anoop,

Because when ever I try to pass date of java.util.date type to bapi, it gives a complier error. "Type mismatch error appears".

Regards

Arjun

Former Member
0 Kudos

Hi,

Pls pass the java.sql.Date as explained by srinivas.

java.sql.Date dt=new Date(d.getTime());

AM

srinivas_sistu
Active Contributor
0 Kudos

Hi,

In the code I gave you I used yyyy-MM-dd format that is why date is coming in yyyy-MM-dd format, so change that format...

like this

java.util.Date d=null;

d=new SimpleDateFormat("ddMMyyyy").parse(strDate);

java.sql.Date dt=new Date(d.getTime()); // if you need a SQL date...

now you will get the output...

Regards,

SrinivaS

arjun_thakur
Active Contributor
0 Kudos

Hi,

Still no good.

Former Member
0 Kudos

Hi

Could you please post the piece of code you have written with all the imports.

Because the code that i have posted is working. For "Date" , the you need to import "import java.sql.Date;"

Thanks

Ritushree

Former Member
0 Kudos

Hi,

If possible give me the below details:

What is the type of date attribute you are getting from backend? & What is the date format of that?

What is the expecting date type of bapi input? & What is the date format of that?

Regards,

Charan

arjun_thakur
Active Contributor
0 Kudos

HI Charan,

What is the type of date attribute you are getting from backend? & What is the date format of that?

I am getting the value of date by executing a bapi and then I am setting the date vaue to an attribute which is of java.sql.date type and the format is yyyy-mm-dd.

What is the expecting date type of bapi input? & What is the date format of that?

The expecting date type is java.sql.date type and the expected format is ddmmyyyy.

Please help.

Regards

Arjun