Solved

Using date properties?

Posted on 2004-10-14
11
170 Views
Last Modified: 2010-03-31
I want to read a file if it is created between a particular period.The user selects the from and to fields.We compare these two fields with the date in the file.

This is what I am currently doing...

if(rD.after(toDate) && rD.before(tfromDate)){

read the file

}

If the user enters july 01 2004 as the from field, the files are being read from july 02 2004. Can you please help me with this issue?

Thanks,
0
Comment
Question by:g46905
  • 6
  • 5
11 Comments
 
LVL 92

Expert Comment

by:objects
ID: 12312940
if (rD.compareTo(toDate)<=0 && rD.compareTo(tfromDate)>=0)
0
 

Author Comment

by:g46905
ID: 12313831
It is still not reading the file created on that partucular date.

This is what I am using

  rD : Wed Sep 01 00:00:00 CDT 2004 // the file created on the same date as fromDate is not being read.
 fromDate : Wed Sep 01 00:00:00 CDT 2004
 ToDate : Thu Sep 30 23:59:59 CDT 2004

if ((rD.compareTo(toDDDDt)<=0) && (rD.compareTo(frDDDDt)>=0))

Any ideas would be greatly appreciated.

Thanks,
0
 
LVL 92

Expert Comment

by:objects
ID: 12313856
can you run this and post the output:

System.out.println(rD);
System.out.println(frDDDDt);
System.out.println(toDDDDt);
System.out.println(rD.compareTo(toDDDDt));
System.out.println(rD.compareTo(frDDDDt));
0
 

Author Comment

by:g46905
ID: 12315625
Object,
          Here are the results that you have asked me for


 rD : Wed Sep 01 00:00:00 CDT 2004
 frDDDDt : Wed Sep 01 00:00:00 CDT 2004
 toDDDDt : Thu Sep 30 23:59:59 CDT 2004
 rD.compareTo(toDDDDt) : -1
 rD.compareTo(frDDDDt) -1

Please let me know if you want me to try something else.Thanks for your help!

Thanks again,
0
 
LVL 92

Expert Comment

by:objects
ID: 12315841
post the results of this:

System.out.println(rD.getTime());
System.out.println(frDDDDt.getTime());
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:g46905
ID: 12316028
System.out.println(rD.getTime());

=>  1094014800000

System.out.println(frDDDDt.getTime());

=>  1094014800219

Please lte me know if you want me to test something.

Thanks
0
 
LVL 92

Accepted Solution

by:
objects earned 50 total points
ID: 12316061
the date isn't actually between those two dates, it is 219 msecs before frDDDDt .
0
 

Author Comment

by:g46905
ID: 12317931
This is how I set the fromDate

cs.set(yyyy, mm, dd, 0, 0, 0);

Could you please share your thoughts on the changes that needs to take place to resolve the above mentioned issue.

Thanks,
0
 

Author Comment

by:g46905
ID: 12317983
I want the milliseconds to be a default value of 0 all the time for the fromDate. Can you please suggest?

Thanks
0
 

Author Comment

by:g46905
ID: 12318080
I have made the change required and was able to set the milliseconds to default 0.Thanks for all your help.

cs.set(Calendar.MILLISECOND,0);

Thanks again,
0
 
LVL 92

Expert Comment

by:objects
ID: 12324395
good to hear you got it resolved :)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
topping1 challenge 7 72
wordappend challenge 8 143
Java and GPO 11 68
github account with ecipse 1 42
For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now