on 02-01-2007 9:14 AM
Hi Guys
Can anybody tell me how can we check that the date user is entering is greater than current system date.... i have used Date Navigator.. Can anybody guide me how to apply Validation on date ?
Thanks
Puneet
hi,
to get the current date
Date sqlDate = new Date(System.currentTimeMillis());
if (wdContext.currentContextElement().getDate().after(sqlDate ))
{
wdComponentAPI.getMessageManager().reportException("Please enter current date or future date", false);
}
Regards,
Gopi
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
hi puneet,
try this also
//get system date like this :
java.util.Date today = new java.util.Date();
SimpleDateFormat formatter = new SimpleDateFormat("MM/dd/yyyy");
String datenewformat = formatter.format(today);
java.util.Date date2 =null;
try
{
date2 = formatter.parse (datenewformat);
logger.infoT(" current date : "+date2);
}
catch(Exception pe)
{
pe.printStackTrace();
}
// now get date the user has enteres like this
String enteredDateStr = wdContext.currentContextElement().getAttributeAsText("Date");
//
java.util.Date date = null;
int dateInt=0;
SimpleDateFormat formatterNew = null;
if(enteredDateStr!=null&&!enteredDateStr.equals(""))
{
// Convert string to Date format
try
{
formatterNew = new SimpleDateFormat("MM/dd/yyyy");
date = formatterNew.parse(enteredDateStr);
dateInt = date.compareTo(date2);
}
catch(Exception e)
{
logger.infoT(" not a proper date format hence cannot convert");
IWDMessageManager messageMan = (IWDMessageManager) wdComponentAPI.getMessageManager();
messageMan.reportInvalidContextAttributeException(contextElemet,dateStrAttribute," Please enter the date in the following format MM/DD/YYYY ",true);
}
//Compare the 2 dates
if(dateInt<0)
{
IWDMessageManager messageMan = (IWDMessageManager)wdComponentAPI.getMessageManager();
messageMan.reportInvalidContextAttributeException(contextElemet,dateStrAttribute," cannot be lesser than current date ",true);
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
86 | |
10 | |
10 | |
9 | |
6 | |
6 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.