cancel
Showing results for 
Search instead for 
Did you mean: 

Date Validation

former_member720137
Active Participant
0 Kudos

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

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

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

former_member720137
Active Participant
0 Kudos

Hi

Thanks Gopi... 10 points for u...

Regards

Puneet

Answers (1)

Answers (1)

Former Member
0 Kudos

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

}

}