cancel
Showing results for 
Search instead for 
Did you mean: 

Reg: Assigning a Date value in context

Former Member
0 Kudos

Hi,

Below is the code, where i am initializing a context with the date value. But the date value is not getting assigned to the context. What could be the problem? Kindly help me out.

String s = "12/31/9999";

try {

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

java.sql.Date date1 = (java.sql.Date)sd.parse(s);

Calendar c = Calendar.getInstance();

c.set(2006, 8, 22); //month is zero based

java.sql.Date date2 = (java.sql.Date)c.getTime();

wdContext.currentContextElement().setValidto(date1);

}

Thanks & Regards.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Dhana,

Try this:


String s = "12/31/9999";
try {
/* 
//NOT USED ??? 
SimpleDateFormat sd = new SimpleDateFormat("MM/dd/yyyy");
java.sql.Date date1 = new java.sql.Date( ((java.util.Date)sd.parse(s)).getTime());
*/
Calendar c = Calendar.getInstance();
c.set(2006, 8, 22); //month is zero based
java.sql.Date date2 = new java.sql.Date(c.getTimeInMillis());
wdContext.currentContextElement().setValidto(date2);
}

WD in fact requires java.sql.Date, but many Java API returns java.util.Date and you may not upcast java.util.Date to java.sql.Date

Valery Silaev

SaM Solutions

http://www.sam-solutions.net

Answers (2)

Answers (2)

Former Member
0 Kudos

Makesure that your code is in init() method

Regards, Anilkumar

Former Member
0 Kudos

Dhana,

Are you sure you are using correct variable in last statement (date1 or date2)?

wdContext.currentContextElement().setValidto(date2);

VS

Former Member
0 Kudos

Hi,

I want that date1 value to be set in my context. I have written my code only in init method. But is not getting set to the context. What cud be the problem?

Thanks & Regards,

Dhana

Former Member
0 Kudos

Hi,

String s = "12/31/9999";

try {

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

java.sql.Date date1 = new java.sql.Date( ((java.util.Date)sd.parse(s)).getTime());

Calendar c = Calendar.getInstance();

c.set(2006, 7, 22); //month is zero based

java.sql.Date date2 = new java.sql.Date(c.getTimeInMillis());

wdContext.currentContextElement().setRam(date1);

wdComponentAPI.getMessageManager().reportSuccess("hi"+wdContext.currentContextElement().getRam());

wdComponentAPI.getMessageManager().reportSuccess("hi4"+ date2);

}

this should helps you.

Thanks,

Lohi.