cancel
Showing results for 
Search instead for 
Did you mean: 

Initialize Date

Former Member
0 Kudos

hi

i am trying to initialize an input field of type date(ie bound to a context of type date)

wdContext.currentContextElement().setVa_fromdate(xxxxx);

what do i write in place of xxxxx

Plz help

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Himanshu,

You can use the following code:

//You can get current date

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

//You can set your context like this:

wdContext.currentContextElement().set<attribname>(currDate);

Thanks n Regards,

Jhansi Miryala

Answers (4)

Answers (4)

Former Member
0 Kudos

Hi,

Since you have taken a context attribute of date type,so this attribute accepts a value of date format only.so cant give any data to this context attribute.

To set this attribute with current date, you can use following code:

java.sql.Date date = new java.sql.Date(new java.util.Date().getTime());

wdContext.currentContextElement().set<attributename>(date);

For your information,this will not set the attribute with system date instead it will set the date of sql server.

if you want to set this attribute with system date,then use below mentioned code:

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

wdContext.currentContextElement().set<attributename>(sysDate);

regards,

amit bagati

Former Member
0 Kudos

Hi himangshu,

Use this code



//Date of type java.sql.Date

//for setting the current date
java.sql.Date date;
wdContext.currentContextElement().setDate( date = new Date(  System.currentTimeMillis()));
    
//sets the custom date 
  Calendar calendar = Calendar.getInstance();
  calendar.set( 2008, 05, 02);
  wdContext.currentContextElement().setDate( new Date( calendar.getTimeInMillis()));

Regards

Vinod V

nikhil_bose
Active Contributor
0 Kudos

if the attribute type is date you need to set java.sql.Date instance in the set method


//for current system date:
   Date current = new Date(System.currentTimeMillis());

//for a date of your choice:
   Calendar cal = Calendar.getInstance();
   cal.set(1998,10,01);
   Date old = new Date (cal.getTimeInMillis());


wdContext.currentContextElement().setVa_fromdate(xxxxx);
 // you can set current or old as parameter

nikhiL

snehal_kendre
Active Contributor
0 Kudos

HI Himanshu,

Never initialize you date with someother date.

Best way is to initialize it with todays date..i.e.current date.

if your date type is sql.date then

java.sql.Date l_sqlD = new java.sql.Date(new java.util.Date().getTime());