cancel
Showing results for 
Search instead for 
Did you mean: 

Today's date in mm-dd-yyyy format

Former Member
0 Kudos

Hi,

The default date format in my case is yyyy-dd-mm. I want to pass today's date in the format mm-dd-yyyy to a FM in R3. I have gone through many threads but most talk about changing the format from date to string and vice-versa. Others say that we can pass the date in any format and R3 would take care of that. But in my case, these solutions have not helped. I tried converting todays date to string and then string to date in the req format using SimpleDateFormat class but it throws an exception. Would really appreciate if someone could send me a piece of code to address this issue.

Regards,

Prathamesh

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi

Create a Simple type dictionary item

and set Representation as <b>MM-dd.yyyy</b>

please note that you need to give month in capital letters ie in MM

java.util.Date dt=new java.util.Date();
sqlDate=new java.sql.Date(dt.getTime());

set sqlDate to date simple type

Regards

Chaitanya.A

Answers (5)

Answers (5)

ankur_garg5
Active Contributor
0 Kudos

Hi Prathamesh,

I have faced similar problem. Please try this simple solution. Suppose your date is in format yyyy-dd-mm. If it is in string format, then its ok, otherwise first convert it to string using toString() function as shown below. After that try using the code which I have given below. The only thing that is required to be done after that is the input parameter of your FM must be of string type. Once that is done, pass new_date as input parameter to your FM.

<b> String temp_date = date.toString();

String temp_day = temp_date.substring(5,7);

String temp_month = temp_date.substring(8,10);

String temp_year = temp_date.substring(0,4);

String new_date = temp_day"-"temp_month"-"temp_year;</b>

Let me know if you have any other query.

Bye

Ankur

Message was edited by:

Armin Reichert

Former Member
0 Kudos

Hi Prathamesh,

Please check the datatype of date in model.

If it is String and needed of form MM-dd-yyyy, use the following:

java.util.Date date_curr = Calendar.getInstance().getTime();

SimpleDateFormat sd_out = new SimpleDateFormat("MM-dd-yyyy");

String date_out = sd_out.format(date_curr);

If the input needed is Date, then just converting it to Util.Date will do

then uyou could directly use date_curr.

Do post back if it is needed in any other format

Regards,

Smruti

former_member751941
Active Contributor
0 Kudos

Hi Prathamesh,

Check this code.

try {

Date current_Date = new Date (System.currentTimeMillis());

modelDetails.setCurrDate(new Date(smpdtFormat.parse(current_Date.toString()).getTime()));

} catch (ParseException e1) {

// TODO Auto-generated catch block

e1.printStackTrace();

}

//@@begin others

SimpleDateFormat smpdtFormat = new SimpleDateFormat("MM-dd-yyyy");

//@@end

Regards,

Mithu

Former Member
0 Kudos

Hi Prathamesh,

Have you tried creating a simple type of date and the type of the context is set to the simple type.

Under simple type> Representation Tab> specify the format.

Regards,

Murtuza

Former Member
0 Kudos

Hi..

chk this..

u might get some idea..

Regards,

Gs