This week's book giveaway is in the OCAJP forum.
We're giving away four copies of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) and have Khalid A Mughal & Rolf W Rasmussen on-line!
See this thread for details.
Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Program for date comparison

 
sridhar Ranganathan
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 15440
41
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Code tags on JavaRanch require [ and ] brackets, not < and >.

But why are you posting this here, do you have a question?
 
sridhar Ranganathan
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic