| 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
Bartender
Joined: Aug 16, 2005
Posts: 12911
|
|
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
|
 |
 |
|
|
subject: Program for date comparison
|
|
|