File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Program for date comparison Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Program for date comparison" Watch "Program for date comparison" New topic
Author

Program for date comparison

sridhar Ranganathan
Greenhorn

Joined: Feb 06, 2008
Posts: 29
Hi,
I have attached the code of date comparison,somebody asked this pgm.
Iam unable to post this.

In this pgm ,Getting two dates(from and to) input from console storing in string variable.comparing the two date fields.

<code>
import java.util.*;
import java.io.*;
import java.text.ParseException;
import java.text.SimpleDateFormat;
class dc
{
public static void main(String ae[])throws IOException
{
try
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter the From Date [Format DD-MM-YYYY]");
String fromDate=br.readLine();
System.out.println("Enter the To Date [Format DD-MM-YYYY]");
String toDate=br.readLine();
SimpleDateFormat form=new SimpleDateFormat("dd-MM-yyyy");
Date sysdate=new Date();
System.out.println("\n========================================================");
System.out.println("\t\tDATE COMPARISON ");
System.out.println("========================================================");
System.out.println("\tFROM DATE :- "+form.format(form.parse(fromDate)));
System.out.println("\tTO DATE :- "+form.format(form.parse(toDate)));
System.out.println("======================================================== ");

if(form.parse(fromDate).before(form.parse(toDate)))
{
System.out.println("\tFROM DATE IS LESS THEN TO DATE ");
}
else
{
System.out.println("\tFROM DATE IS GREATER THEN TO DATE ");
}
System.out.println("======================================================== ");
}
catch(ParseException pe)
{
System.out.println("Parse Exception : " + pe);
}
}
}
</code>


Thanks,
Sridhar.R
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 13868
    
  10

Code tags on JavaRanch require [ and ] brackets, not < and >.

But why are you posting this here, do you have a question?


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
sridhar Ranganathan
Greenhorn

Joined: Feb 06, 2008
Posts: 29
Hi,

Somebody asked this program,Iam unable to reply to him.That is why i posted
here.This will help for someone.

Thanks
Sridhar.R
 
jQuery in Action, 2nd edition
 
subject: Program for date comparison
 
Similar Threads
Any Alternative for this CODE !!!!!!
Date; Previous date, Calendar; Gregorian
Problem in setting the date in a servlet
how to convert a string to date
Date manipulation problem