• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Comparing dates...

 
Daniel Harris
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I subtract a date that is recent (a few weeks) from today's date, I get a negative number returned.



getTimeInMillis() returns a negative number if the date of entryDate is within the past few weeks.

Can anybody tell me why?
 
Rob Spoor
Sheriff
Pie
Posts: 20514
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It should only return a negative value if the date is before 00:00:00 GMT on January 1st 1970. This date time is also called the epoch - see java.util.Calendar for more info. This point of time is represented as 0 in Java's calendars and dates (among others; PHP also uses it). Any time before that is always negative.

That still does not explain why a few weeks ago is negative. Can you tell us what values you are using when creating the GregorianCalendar?
 
Daniel Harris
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks or replying!

Heres an example that returns a negative number...


then == a negative number.

Like I said though... it only does this if the past date is within a few weeks.
 
Paul Clapham
Sheriff
Posts: 20990
31
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But that's not a "past date". It's March 23 of this year and we haven't got there yet.
 
Daniel Harris
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Clapham wrote:But that's not a "past date". It's March 23 of this year and we haven't got there yet.



Ahhh.... I see says the greenhorn! Thanks!
 
Rob Spoor
Sheriff
Pie
Posts: 20514
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is exactly why you can better use the Calendar constants like Calendar.FEBRUARY.
 
Daniel Harris
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Prime wrote:This is exactly why you can better use the Calendar constants like Calendar.FEBRUARY.


The calendar is created with variables... The constants dont apply here. Thanks for the advice though!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic