on 03-08-2010 1:46 PM
Hi All,
I want to validate one of the date fields in my application. I need to check if start date is not before today's date for which i have written the following code:
Date dtStartDate = wdContext.currentContextElement().getStartDate();
Date sqlCurrDate = new Date(System.currentTimeMillis());
if(dtStartDate.before(sqlCurrDate))
{
---messageManager.reportException("Start Date is before Today's Date...");
}
this works fine if i select any day before current date, but this message displays even if i have selected today's date in the UI element, which is not what i want
I tried the same using compare(), equals(), but the same result.
the NWDS used is CE 71. composition environment SP06. Does this have anything to do with the above behavior?
Kindly let me know if there is any other way to achieve this functionality?
Regards,
Poojith MV
Edited by: Poojith M V on Mar 8, 2010 2:48 PM
Hi Poojith
Please print dtStartDate and sqlCurrDate using MessageManager and check the result. then compare result with method.
Hope this will helps you.
Regards,
Arun Jaiswal
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Arun,
I tried printing both the dates using messagemanager, if the selected date is 08/03/2010 and the current date is 08/03/2010. it prints the same date, but when i print the comparision result, the following is printed:
1. dtStartDate--08/03/2010, Current Dste -- 09/03/2010, result-- false
2. dtStartDate--10/03/2010, Current Date -- 09/03/2010, result-- true
3. dtStartDate-- 09/03/2010, Current Date -- 09/03/2010, result - false
This is the problem, even if i have selected the current date, the result of comparision is false.
Regards,
Poojith MV
Hi Poojith,
I think the problem is caused by the fact that your start date represents the time the actual day started (so midnight), whereas your current date includes the actual time (and Date method before compares milliseconds). Please try substituting your check with the following version and let us know if this works as you want:
if(!sqlCurrDate.after(dtStartDate)) {
---messageManager.reportException("Start Date is before Today's Date...");
}
Cheers, harald
Problem solved!!!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
selecting date you choose also time - so you probably get midnight for today's date, and current time for System.currentTimeInMilis().
In this case, you check if today's midnight is before current date and time - which is true.
To solve your problem, you should reset time in current time, or compare tommorow's date and midnight.
Regards,
--
Przemysław
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
85 | |
10 | |
10 | |
10 | |
7 | |
6 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.