Skip to Content
author's profile photo Former Member
Former Member

Initialize Date

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

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

5 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on May 02, 2008 at 06:37 AM

    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

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on May 02, 2008 at 06:35 AM

    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());

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on May 02, 2008 at 06:50 AM

    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

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on May 02, 2008 at 07:00 AM

    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

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on May 02, 2008 at 07:07 AM

    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

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.