File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes checking for date Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "checking for date" Watch "checking for date" New topic

checking for date

lynn fann
Ranch Hand

Joined: Oct 15, 2006
Posts: 115
i need to check whether the date is 6 month ago from the today date. How should i check it?
Deepak Bala

Joined: Feb 24, 2006
Posts: 6662

Use the Calendar class

SCJP 6 articles - SCJP 5/6 mock exams - More SCJP Mocks
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 15092

Have a look at the documentation for class java.util.Calendar. With that class, you can do this:
  • Get an instance of Calendar that represents the current date and time
  • Subtract 6 months from the current date and time of the Calendar
  • Compare the date and time of the Calendar to that of a Date object

  • So have a look at class Calendar and try to write some code. If you have more questions, please ask them here.
    [ March 21, 2007: Message edited by: Jesper Young ]

    Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
    lynn fann
    Ranch Hand

    Joined: Oct 15, 2006
    Posts: 115
    i know is using calendar class. i dont know how to substract 6 month. is it that i have to get the milliseconds for 6 mth, and use the current to substract?
    Garrett Rowe
    Ranch Hand

    Joined: Jan 17, 2006
    Posts: 1296
    Have you taken a look at the Calendar.add()?

    Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peter
    I agree. Here's the link:
    subject: checking for date
    It's not a secret anymore!