This forum is closed to new posts and responses. Individual names altered for privacy purposes. The information contained in this website is provided for informational purposes only and should not be construed as a forum for customer support requests. Any customer support requests should be directed to the official HCL customer support channels below:

HCL Software Customer Support Portal for U.S. Federal Government clients
HCL Software Customer Support Portal



Apr 15, 2011, 12:38 PM
16 Posts

Re: Dates comparison issue

  • Category: Debugging
  • Platform: All
  • Release: 8.5.2
  • Role:
  • Tags:
  • Replies: 6
Hi
 
Dates have always been interesting and at times challenging to get working - especially for all of us not living in the US (!). Just this morning I found an error in the LotusScript Format method that will use the American algorithm to calculate week numbers (no matter what the Notes client has been set to use...). In Europe we have use the ISO standard to return the correct week number. Yes, week numbers actually differ between the US and Europe (for this and last year). Sigh!
 
But back to your question. It all comes back to the format of the date. I do not know what conversions you have made. From the dates you have specified it is impossible to say whether the format is: dd.mm.yy, mm.dd.yy, or yy.mm.dd. In the last format your logic is actually true... ;-) The next thing that could trick you (but not with the examples you have given) is that the (built-in) code may try to "help" you. This was true for the first versions of the webservice classes in version 7 where the date 2010-10-31 was correctly interpreted as a date in October, whereas the date 2010-11-04 incorrectly was interpreted as a date in April (both using the date format yyyy-mm-dd which is the "normal" for XML dates) - sigh, again...!
 
I suggest you try to ensure that your date formats are enforced. One way of doing this (say if you are converting between strings and date objects) is to create a date with a format that you know, say 1999-12-31 and then you can substitute your date values into the string using a simple string replacement and really ignore the format that the current computer was using. On a server you may be able to control it - but if your application is run on more than one computer you may inevitably end up with these kind of challenges...
 
/John 
Apr 15, 2011, 1:01 PM
29 Posts
Re: Dates comparison issue
Thank you for the response!
My mistake, I really did not specify the format in my example, it was dd.mm.yy %-)
I will try to use your advice and get back with the results! 

Apr 15, 2011, 1:59 PM
29 Posts
Re: Dates comparison issue
 Hi again,
 
didn't work. What I did was: 
1) i got 3 dates : 2 from fields on Xpage, 1 from NotesDocument to make a comparison : (1)xPage<=documentDate<=(2)xPage
2) Got .toString representation of all the 3 dates
3) sent them to the function which formatted them all as dd.mm.yy:
 
var dat1=new Date(); 
dat1.setDate(date.left(2));
dat1.setMonth(date.mid(3,2)-1);
dat1.setFullYear(date.right(4));
 
4) I checked values via console: (1) xPage = 31.12.10 , documentDate=01.02.11 , (2)xPage = 01.03.11
5) then I get the already mentioned result of comparison: 
31.12.10 <=01.02.11 False 
01.02.11 <= 01.03.11 True 
Apr 15, 2011, 2:20 PM
29 Posts
Re: Dates comparison issue
Turned out to be tricky, but the only method which worked was applying    .valueOf()  to the dates and comparing the numeric representation.
It worked only this way. 
Apr 15, 2011, 2:50 PM
261 Posts
Re: Dates comparison issue
Hi Ruslan,
 
If you want to compare Java dates, you can also use the getTime() method (which returns number of milliseconds since midnight of January 1, 1970) or use the compareTo() method.
 
To easily transform a NotesDateTime object to a Java date you can use the NotesDateTime.toJavaDate() method.
 
 
Apr 15, 2011, 3:01 PM
29 Posts
Re: Dates comparison issue
 Hi, Mark! I wish I had known about conversion earlier. I used to work mostly with LotusScript till now and it's my first time I get into this kind of trouble %-)
Thank you for the advice, guys! You're all really helpful here! 

This forum is closed to new posts and responses. Individual names altered for privacy purposes. The information contained in this website is provided for informational purposes only and should not be construed as a forum for customer support requests. Any customer support requests should be directed to the official HCL customer support channels below:

HCL Software Customer Support Portal for U.S. Federal Government clients
HCL Software Customer Support Portal