cancel
Showing results for 
Search instead for 
Did you mean: 

Date problem

Former Member
0 Kudos

Hi,

I have a view with an input field for date.

The input field is bound to a value attribute of type Date.

Initially, when the view is displayed, I want the field to be populated with current date in the format mm/dd/yyyy.

Can anyboby let me know how you can obtain the current date ( only mm/dd/yyyy ) and diplay it in the input field?

Thanks in advance,

Reena

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

in wdDoInit of view:


wdContext
  .currentContextElement()
    .set<DateAttributeName>
    (
       new java.sql.Date( System.currentTimeMillis() )
    );

VS

Answers (4)

Answers (4)

Former Member
0 Kudos

Hi all,

Thanks a ton for the help. I was able to solve the problem.

Special thanks to Valery !

Regards

Reena

Former Member
0 Kudos

Hi Reena,

you can get the full date in this format like :: 09/22/2005

String date = (new SimpleDateFormat("MM/dd/yyyy").format(new java.util.Date()));

So now set this value to ur context attribute.

create a value attribute in the context of type string(dt), bind this to the input field, and in the implementation part of Init method add this code.

wdContext.currentContextElement().setDt(date);

(be sure that yyyy and dd are small letters)..

All the best.

Regards,

Sirisha.R.S

Former Member
0 Kudos

HI Reena,

Write following code to set current date value.

wdcontext.currentcontextelement().set<attribute>(new Date());

Regards,

Bhavik

Former Member
0 Kudos

Hi Reena,

Check the Answer in earlier post

Regards,

Shubham

Former Member
0 Kudos

Hi Reena,

Sorry I misread the question.

Regards,

Shubham

Former Member
0 Kudos

Hi Valery,

Thanks a lot. I have awarded full points

I have another question.

How do I get the date exactly 1 month prior to the current date? (In the same format mm/dd/yyyy)

Because I actually have two input fields.

"From Date" and "To Date".

I was able to populate the "To Date" field with ur help.

Now I need to populate the "From Date" field with the date exactly 1 month prior to the current date.

Thanks in advance.

Regards,

Reena

Former Member
0 Kudos
final long now = System.currentTimeMillis();
final java.sql.Date till = new java.sql.Date(now);
final Calendar c = Calendar.getInstance
( 
  WDResourceHandler
    .getCurrentSessionLocale() 
);
c.setTimeInMillis( now );
c.add( Calendar.MONTH, -1 );

final java.sql.Date from = new java.sql.Date( c.getTimeInMillis() );

Good luck!

Valery Silaev

EPAM Systems

http://www.NetWeaverTeam.com