cancel
Showing results for 
Search instead for 
Did you mean: 

Dateformat Error

Former Member
0 Kudos

Hi Friends,

In Portal calender side that Date format show like (mm/dd/yyyy) like that i need display the date format in portal calender(dd/mm/yyyy) like this. So i have to done some code here

Ymm_Sc_Bapieindt delvDateRange = new Ymm_Sc_Bapieindt();

wdContext.nodeDaterange().bind(delvDateRange);

SimpleDateFormat sdfDate = new SimpleDateFormat("DD/MM/YYYY");

String datestr = sdfDate.format(new java.util.Date());

delvDateRange.setFrom_Date(datestr);

delvDateRange.setTo_Date(datestr);

input.addDaterange(delvDateRange);

i am getting Error here.

delvDateRange.setFrom_Date(datestr);

delvDateRange.setTo_Date(datestr);

That error is This method setFrom_Date/setTo_Date(Date) in the type Ymm_Sc_Bapieindt is not applicable for the arguments (String)

I m getting this error

How to slove this

Regards

Vijay

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Vijay,

You can just parse the date into which ever format you like.


Date startDate = null;
String strStartDate = null;

strStartDate = wdContext.currentNode_Element().getValueAttriute();

DateFormat df = new SimpleDateFormat("dd/MM/yyyy");
try {
	startDate = df.parse(strStartDate);
}	       
catch (ParseException e) {
wdComponentAPI.getMessageManager().reportException("Error in Formatting the Date",false);
}

Hope this helps you.

Regards,

p188071.

Former Member
0 Kudos

Hi,

I m doing like this

SimpleDateFormat sdfDate = new SimpleDateFormat("DD/MM/YYYY");

String datestr = sdfDate.format(new java.util.Date());

delvDateRange.setFrom_Date(datestr);

delvDateRange.setTo_Date(datestr);

input.addDaterange(delvDateRange);

here datestr shows:datestr:::08/04/2010 like this i need to display in calender this format.

next what can i dooo.. can u tell exact codeing

Regards

Vijay

p330068
Active Contributor
0 Kudos

Hi Vijay,

Please try to convert datestr in date format and use it as set parameter for delvDateRange.

Hope it helps

Regards

Arun

Former Member
0 Kudos

Hi Arun

I am struck in that part (convert datestr in date format). I m finding but I m not gettingu2026Can u tell me

How to convert datestr in date format . I am trying yesterday also but i m not getting proper out put pls tell me

Regards

Vijay

p330068
Active Contributor
0 Kudos

Hi Vijay,

Please try this :-

SimpleDateFormat sdfDate = new SimpleDateFormat("DD/MM/YYYY");

String datestr = sdfDate.format(<Format the date as per sdfDate format - DD/MM/YYYY like wdContext.currentContextElement().get<ATTRIBUTE Name>() WHICH you want to format>);

Date n_date = new Date(datestr);

delvDateRange.setFrom_Date(n_date); ->> if From_Date only accept Data parameter.

Refer to http://techtracer.com/2007/03/28/convert-date-to-string-and-string-to-date-in-java/

Hope it helps

Regards

Arun

chander_kararia4
Contributor
0 Kudos

Hi Vijay

This is the basic concept in Java coding which do not require any special wd concepts or anything. Only requirement is -- First you must know exactly what you need to achieve & what it will take to achieve.

Here is the example -


public class StringToDate 
{ 
public static void main(String[] args) 
{ 
DateFormat df = new SimpleDateFormat("dd/MM/yyyy"); 

try
{ 
Date today = df.parse("08/04/2010");             
System.out.println("Today = " + df.format(today)); 
} catch (ParseException e) 
{ 
e.printStackTrace(); 
} 
} 
}

And here is the result of our code:

Today = 08/04/2010

Let me explain you as I guess you might not know what this code is actually doing.

The example starts by creating an instance of SimpleDateFormat with "dd/MM/yyyy" format which mean that the date string is formatted in day-month-year sequence.

Finally using the parse(String source) method we can get the Date instance. Because parse method can throw java.text.ParseException exception if the supplied date is not in a valid format; we need to catch it.

Following are the imports you need to make


import java.text.DateFormat; 
import java.text.SimpleDateFormat; 
import java.text.ParseException; 
import java.util.Date; 

I really hope this will let you understand few more concepts.

Best Regards

Chander Kararia

  1. If you got the solution, please mark the thread as answered.

Answers (3)

Answers (3)

Former Member
0 Kudos

Hi Vijay ,

1) Instead of Java Coding , Change the User Language Parameters in User administration to English UK , Date will be displayed in dd.mm.yyyy format.

2)Use can Also change the language settings for a system , Goto Control Panel->Regional and Language Options , here Select English (United Kingdom )From Drop down , but this will work only for that desktop.

p330068
Active Contributor
0 Kudos

Hi KalluriVijay

You are setting string value to delvDateRange. it will take the Date parameter.

Please check the below documents :

Hope it helps

Regads

Arun

Former Member
0 Kudos

Hi,

I understand, you are trying pass parameter String (SimpleDateFormat will return String) instead of type Date.

Try to pass the date value to the parameters and check it again.

Regards,

Saravanan K