Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 12-19-2007, 07:34 PM
Member
 
Join Date: Dec 2007
Posts: 8
Rageagainst20 is on a distinguished road
Date comparison
Code:
private void cmdCalculateActionPerformed(java.awt.event.ActionEvent evt) { String datetoday; DateFormat df = new SimpleDateFormat("yyyy-MM-dd"); int modifier = 0; Date d1; Date d1last; Date d1normal; Date d1discount; Date d2; Date d2last; Date d2normal; Date d2discount; Date d3; Date d3last; Date d3normal; Date d3discount; Date d4; Date d4last; Date d4normal; Date d4discount; Date todaysdate; datetoday = new SimpleDateFormat("yyyy-MM-dd").format(new java.util.Date()); try { todaysdate = df.parse(datetoday); d1 = df.parse("2007-01-01"); d1last = df.parse("2007-03-31"); d1normal = df.parse("2007-03-15"); d1discount = df.parse("2007-03-24"); d2 = df.parse("2007-04-01"); d2last = df.parse("2007-06-30"); d2normal = df.parse("2007-06-15"); d2discount = df.parse("2007-06-23"); d3 = df.parse("2007-07-01"); d3last = df.parse("2007-09-30"); d3normal = df.parse("2007-09-15"); d3discount = df.parse("2007-06-23"); d4 = df.parse("2007-10-01"); d4last = df.parse("2007-12-31"); d4normal = df.parse("2007-12-16"); d4discount = df.parse("2007-06-24"); } catch(java.text.ParseException pe) { JOptionPane.showMessageDialog(null, "like parse error"); return; } String relation; String date1 = d1.toString(); String date2 = d2.toString(); String date3 = d3.toString(); String date4 = d4.toString(); String date1last = d1last.toString(); String date2last = d2last.toString(); String date3last = d3last.toString(); String date4last = d4last.toString(); if (((todaysdate.equals(d1)) | (todaysdate.after(d1))) && ((todaysdate.equals(d1last)) | (todaysdate.before(d1last)))) { relation = ("Date is in the first Quarter"); LblPrevious.setText(date4last); LblCurrent.setText(date4last); } else if (((todaysdate.equals(d2)) | (todaysdate.after(d2))) && ((todaysdate.equals(d2last)) | (todaysdate.before(d2last)))) { relation = ("Date is in the second Quarter"); LblPrevious.setText(date1last); LblCurrent.setText(date2last); } else if (((todaysdate.equals(d3)) | (todaysdate.after(d3))) && ((todaysdate.equals(d3last)) | (todaysdate.before(d3last)))) { relation = ("Date is in the third Quarter"); LblPrevious.setText(date2last); LblCurrent.setText(date3last); } else if (((todaysdate.equals(d4)) | (todaysdate.after(d4))) && ((todaysdate.equals(d4last)) | (todaysdate.before(d4last)))) { relation = ("Date is in the fourth quarter"); LblPrevious.setText(date3last); TxtOutput.setText(todaysdate + " is " + relation ); LblCurrent.setText(date4last); } else if (todaysdate.equals(d1discount)) { JOptionPane.showMessageDialog(null, "discounted", "zxczxczc", JOptionPane.ERROR_MESSAGE); } relation = ("Date is in the fourth quarter"); LblPrevious.setText(date3last); LblCurrent.setText(date4last);

The above works by dectecting which quarter of the year the user by comparing preset dates with todays date. Unfortunately when I tried to test it on other dates for example the "d1discount" date to throw up an errror message it just didnt work it wasnt able to compare the varaible todaysdate to d1discount, even when I set the value of todaysdate to the same as d1discount it won't be able to catch the day why is this.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Difference between current date and anothe date vijay balusamy New To Java 1 04-16-2008 05:15 PM
String comparison abhiN New To Java 2 04-09-2008 05:47 AM
Comparison of Strings Cero.Uno New To Java 3 02-11-2008 03:46 AM
Parsing Dates for Comparison Rageagainst20 New To Java 1 12-19-2007 06:50 AM
String comparison sireesha New To Java 1 12-18-2007 01:16 AM


All times are GMT +3. The time now is 10:43 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org