on 01-05-2006 7:26 AM
Hi
I have a date value returning from Xi thats of the type String, and I need to convert that to type Date so I can populate an input field of type Date(for the purpose of having a date picker in that input field).
How to convert? Request you to give an example.
Thanks
jack
Jack,
I m afraid that this scenario won't work.
U cannot convert a date value of type String to type date and then store it in the input box.
Only option is u can have the input box type to string and then store the value.
Regards,
Nagarajan.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I haven't tried binding a java.util.Date to an input box, maybe it works. I don't have NWDS installed on this computer so I can't easily test.
If it doesn't work you can convert rdate to java.sql.Date and bind the new sql-date to the input box.
java.sql.Date sqlDate = new sqlDate( rdate.getTime());
Pleasy correct me if I'm wrong, since I can't test it.
First, let's be a little bit pedantic and correct the terminology: You do not "bind a Date to an input box", but you bind the "value" property of an input field to a context attribute of (dictionary) type "date".
You cannot bind the "value" property to an attribute of Java native type java.util.Date. Generally, all data binding must be done to dictionary types.
The runtime equivalent to dictionary type "date" is java.sql.Date and not java.util.Date.
To convert types, e.g. from java.util.Date to java.sql.Date,, calculated attributes can be useful.
Armin
Hi Jack,
Split the individual parts of the date into Day, Month and Year. Create a Calendar Object, set each part and from this create a java.sql.Date Object.
Here's some test code
String d = "31";
String m = "06";
String y = "2005";
Calendar c = Calendar.getInstance();
c.set(Calendar.DAY_OF_MONTH, Integer.parseInt(d));
c.set(Calendar.MONTH, Integer.parseInt(m));
c.set(Calendar.YEAR, Integer.parseInt(y));
Date da = new Date(c.getTimeInMillis());
Remember that months in Java start at 0 so "06" in the example there is July.
Regards,
Patrick.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
87 | |
10 | |
10 | |
10 | |
7 | |
6 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.