• Post Reply Bookmark Topic Watch Topic
  • New Topic

using date as condition  RSS feed

 
mitti sharma
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have to use date as a condition

like this
if "thisdate" < date =< "thisanotherdate"
// here date is wht i am reading from input line and thisdate and thisanotherdate are the boudaries between what i need to pick data from my input file.

thank you.
 
Bala jee
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you expain what exactly you need us to tell? Like do you want a code to compare two dates? what is happening when you run your program?
 
Freddy Wong
Ranch Hand
Posts: 959
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use Date object. It implements Comparable interface, so should able to use compareTo().
 
mitti sharma
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have to extract date and get/post from apache log comman format
(194.116.215.20 - - [14/Nov/2005:22:28:57 +0000] "GET / HTTP/1.0" 200 16440)
and then i have to count no of Gets and Posts within particular dates.
so in my program i am able to extract the dates but then i am not able to put the condition for which i need no of counts.

I can post my code if that will make more sense.
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16028
87
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you get the dates as strings? You can use class java.text.SimpleDateFormat to parse the strings into java.util.Date objects. Then you can use methods before() and after() in class Date to check if one date is before or after another date.

Lookup SimpleDateFormat and Date in the Java API documentation.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12542
48
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
note that java does not allow you to do

you have to break it up like so:
 
mitti sharma
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks all for replies.putting together all thoughts i made through this.
I did use SimpleDateFormat and Date.
once again thanks.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!