cancel
Showing results for 
Search instead for 
Did you mean: 

How to Control Date Format?

Former Member
0 Kudos

hi

I have made a inputfield UI element of type date when i put type 020004 on that input field it changes to 02/01/2004 ,but i want to show some error when this kind of entry ,which however is not happening in present case.

How to do it?

please help me.

Regards

Nidhideep

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

You are not getting an error because 02/01/2004 is a valid date.

If you create a simple type in your local dictionary, based on built in Date type, and on the representation tab you specify format: "dd/MM/yyyy" (or "MM/dd/yyyy") you will get the desired format. (Of course the input field must be bound to a context attribute of your custom date type).

Whatever the user types in the input field is mapped to some date. The user should be able to use a date navigator besides typing the date.

You wil have to do error checking yourself. E.g. if the date must be between e.g. 1950 and 2020, you must implement the validation for this yourself.

Good luck!

Former Member
0 Kudos

hi

I am able to change format.But I want to do some computation on my date like if(date1.before(date2))and other different function of date.I am not able to perform that function.I was using java.sql.Date for my previuos computation it works fine but i was in mm/dd/yy.What should i do?

Please help me.

Regards

Nidhideep

Former Member
0 Kudos

Hi,

Your output is a string.Convert into date then you can do the computation

Regards

Saravanan K

Former Member
0 Kudos

????

By creating a simple type in your dictionary, based on built in type date, you should still be able to compare dates using 'before()' and 'after()' functions.

Did you create a simple type? Does it have built in type date? Is your view element bound to this simple type?

Can you provide a code fragment that the compiler does not accept?

Regards, Roelof

sridhar_k2
Active Contributor
0 Kudos

Hi,

Still you can use before , after on the java.util.Date.

Here is a example. I am able to compare on util.Date classes.

String dateAsString = "14/06/2006";

String SecondDate = "18/08/2006";

java.util.Date dateFrom = null;

java.util.Date dateFromSecond = null;

try {

SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");

if (formatter != null && dateAsString != null) {

dateFrom = formatter.parse(dateAsString);

dateFromSecond = formatter.parse(SecondDate);

}

if(dateFrom.before(dateFromSecond)){

wdComponentAPI.getMessageManager().reportSuccess("First");

}else{

wdComponentAPI.getMessageManager().reportSuccess("Second");

}

}catch(Exception e){

}

Regards,

Sridhar

Former Member
0 Kudos

Hi,

Either change the date type to your custom simple type, or work with date formatters that convert dates to string (hence date comparison will not work).

It is much simpler to use a custom simple type, that's my experience.

Good luck.

Roelof

Former Member
0 Kudos

hi

Thanx for so much support i am able to solve my problem.

I have awarded points to you all people.

Thanx again.

bye

Regards

Nidhideep

Answers (0)