on 06-11-2007 9:05 PM
All,
Im checking whether the entered date is in Past or not with below code: The issue is, If i give current date also its giving me an error. If i give future date then no error.
But I want to send an error message only if the date is in past...Is the below code is correct? If not pls correct me..
Date theDate = (Date)
wdContext.currentContextElement().getAttributeValue("fld");
IWDAttributeInfo attributeInfo =
wdContext.getNodeInfo().getAttribute("fld");
if (theDate.before(new Date(System.currentTimeMillis()))) {
//Throw an error message
}
Thanks
BM
Hi Bharathi M
You can simply use this type of code
if (<b>theDate</b>.after(new Date(System.currentTimeMillis())))
{
......
}
<b>theDate</b> is what you provide for checking
Check out for this Link you will have a clear idea
Regards,
Mathan MP
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
inputDate.<b>before</b>(CurrDate) //means the date has to be earlier then todays date and future date. If it is equal to todays date that means it is not before current date it is equal.
Same way goes for <b>after</b>.
So their is no inbuilt method that can check if input date is past/future including current date.
If you application needs then you have to code it u r self as explained in my above reply.
The reason for not accepting the current date is
The system.currentmillisecond will be changing every second.But the date which you have given in the inputfield will have a constant value(ie millisecond,( which is calculated from 1/1/1970))
When the millisecond of the inputfield is compared with current millisecond,the currentmillisecond value will be greater than the date given in inputfield, so the condition become true and raises the Error
Inorder to make your scenario work perfect,
Date theDate = (Date) wdContext.currentContextElement().getAttributeValue("fld");
IWDAttributeInfo attributeInfo =
wdContext.getNodeInfo().getAttribute("fld");
<b>//Do the below changes
Long d1,d2;
D1=new Date(System.currentTimeMillis()).getTime();
D2=theDate.getTime();
If(((d1-d2)/(10006060*24)>0)
{
//Throw Error Message
wdComponentAPI.getMessageManager().reportSuccess("Date given is a Past Date");
}</b>
If you still have doubts
print the values of d1 and d2. You will know.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Try this
String[] currDate = new Date(System.currentTimeMillis()).toString().split("-");
String[] inpDate = wdContext.currentContextElement().getDatein().toString().split("-");
// check if input year is less than current year
if(Integer.parseInt(inpDate[0]) < Integer.parseInt(currDate[0]))
{
wdComponentAPI.getMessageManager().reportException("Please enter future date or present date",false);
}
else if(Integer.parseInt(inpDate[0]) == Integer.parseInt(currDate[0])) // if input year is equal to curr year
{
if(Integer.parseInt(inpDate[1]) < Integer.parseInt(currDate[1])) // check for the month
{
wdComponentAPI.getMessageManager().reportException("Please enter future date or present date",false);
}
else if(Integer.parseInt(inpDate[1]) == Integer.parseInt(currDate[1])) // if month is same
{
if(Integer.parseInt(inpDate[2]) < Integer.parseInt(currDate[2])) // check for date
{
wdComponentAPI.getMessageManager().reportException("Please enter future date or present date",false);
}
}
}
Message was edited by:
Shriram Kabra
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Bharthi,
There's only one way to be positive.Check the type of the date and if it's java.sql.Date change it java.util.Date and I hope you know that this for an obivious reason.
Regards
Amit
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Bharati,
Wat error u r getting? Wat u wrote inside the if block? Can u explain in detail?
Regards
Fahad Hamsa
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi there,
This is happing because the current time is coming with some hours and minutes.
Try the following code:
Calendar c = Calendar.getInstance();
c.set(Calendar.HOUR_OF_DAY, 0);
c.set(Calendar.MINUTE, 0);
c.set(Calendar.SECOND, 0);
c.set(Calendar.MILLISECOND, 0);
Date theDate = (Date) wdContext.currentContextElement().getAttributeValue("fld");
IWDAttributeInfo attributeInfo = wdContext.getNodeInfo().getAttribute("fld");
Date currentDate = new Date(c.getTimeInMillis());
if (theDate.before(currentDate)) {
//Throw an error message
}
Hope it help you!
Regards,
Luciano
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.