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 Spring in Action this week in the Spring 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: 14268
    
  21

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 8 API documentation
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Program for date comparison