cancel
Showing results for 
Search instead for 
Did you mean: 

Reg : Default Date in the InputField

Former Member
0 Kudos

How to set a Todays Date as default in an Inputfield which has the type Date ?

Regards,

Ramganesh.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

You can use the following code:



	long time = System.currentTimeMillis();
	java.sql.Date dt = new java.sql.Date(time);
	wdContext.currentContextElement().setDate(dt);

This will give the current system time of WAS.

regards,

Mahesh

Answers (4)

Answers (4)

Former Member
0 Kudos

Hi,

wdContext.currentContextElement().setDate(new Date(System.currentTimeMillis());

// organize imports and import java.sql.Date class

Its same as everybody answered. Let us know if this doesn't work for u.

Regards,

Aparna .P

Former Member
0 Kudos

Hi

Use DateHelper.java class . You can get this file from net . You add this file to your SRC folder change package name as per you package name . File contents given below...

This will give you all date related information

For example

System date by

DateHelper.getSystemDate()

Diffrence between date in days

DateHelper.getDurationInDays(DateHelper.getSystemDate(), crtdDate)

You can set you conetxt directly by set method and value as DateHelper.getSystemDate()

Regards

Srushti

File content

/*

  • Created on 16.07.2004

*

  • To change the template for this generated file go to

  • Window>Preferences>Java>Code Generation>Code and Comments

*/

package sap.test.list;

import java.sql.Date;

import java.util.Calendar;

import java.util.GregorianCalendar;

/**

  • @author d025977

*

  • To change the template for this generated type comment go to

  • Window>Preferences>Java>Code Generation>Code and Comments

*/

public class DateHelper {

/**

  • Checks, if Date d1 is before Date d2

  • @param d1 Date

  • @param d2 Date

  • @return "true", if d1 is before d2, else "false"

*/

public static boolean isBefore(Date d1, Date d2) {

return (getDurationInDays(d1, d2) < 0);

}

/**

  • Checks, if Date d1 is after Date d2

  • @param d1 Date

  • @param d2 Date

  • @return "true", if d1 is after d2, else "false"

*/

public static boolean isAfter(Date d1, Date d2) {

return (getDurationInDays(d1, d2) > 0);

}

/**

  • Checks, if Date d1 is equal to Date d2

  • @param d1 Date

  • @param d2 Date

  • @return "true", if d1 is equal to d2, else "false"

*/

public static boolean isEqual(Date d1, Date d2) {

return (getDurationInDays(d1, d2) == 0);

}

/**

  • Checks, if Date d is in the past

  • @param d1 Date

  • @return "true", if d is before system date

*/

public static boolean isInPast(Date d) {

return (getDurationInDays(d, getSystemDate()) < 0);

}

public static Date getSystemDate() {

return new Date(System.currentTimeMillis());

}

/**

  • Simple verification

  • @param dt Date

  • @return "false" if dt==null, else "true"

*/

public static boolean isValid(Date dt) {

if(dt==null) return false;

return true;

}

/**

  • Calculates the difference between Date d1 and Date d2 in days

  • @param d1 Date

  • @param d2 Date

  • @return long days

*/

public static long getDurationInDays(Date d1, Date d2) {

Calendar cal1 = new GregorianCalendar();

cal1.setTime(d1);

long lDat1 = cal1.getTimeInMillis();

Calendar cal2 = new GregorianCalendar();

cal2.setTime(d2);

long lDat2 = cal2.getTimeInMillis();

long days = (lDat1 - lDat2) / 86400000;

return days;

}

}

Former Member
0 Kudos

Try this,

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

wdContext.currentContextElement().setCustomDate(currDt);

Thanks,

Lohi.

Former Member
0 Kudos

Hi,

Use this in wdDoInit:

long millis = System.currentTimeMillis();
    	
Date currDate = new Date(millis);
    	
wdContext.currentContextElement().set<attribute>(currDate);

Regards,

Satyajit.