Solved

Using date properties?

Posted on 2004-10-14
11
172 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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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
 

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
oracle 11g 23 107
How to convert String matching to regex in java 4 51
ejb wildfly example 2 28
Notify sent to other threads in Java 9 34
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

821 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