Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 274
  • Last Modified:

operation on date

hello!experts...
    my problem is this...
    i have a store and i accept new members...once the membership is approved i would store the date when a particular member have been approved.. then after that i would have to keep track if the member is already in its one year so that i could give the member some discounts....how would i do it in java 1.3?
     please do help me...
     thank you...

0
lovelykim
Asked:
lovelykim
2 Solutions
 
lovelykimAuthor Commented:
i would really be glad to have your answers...thanks...
0
 
umangjoshiCommented:
u can use sql query to solve ur problem..

[1] in case of oracle

select date1 - date2 as days from ....

the above returns the difference between two dates in no of days...

[2] the same thing using mysql

select to_days(date1) - to_days(date2) as days from ...

0
 
kennethxuCommented:
1. use java.util.Date or it's subclass java.sql.Date to store/retrieve member join date to file or DB, e.g.
ResutSet rs = .....
Date joinDate = rs.getDate("joinDate");

PreparedStatement ps = .....
ps.setDate( 1, joinDate );

2. use java.text.SimpleDateFormat to convert between String and Date object, for example:
SimpleDateFormat df = new SimpleDateFormat( "MM/dd/yyyy" );
Date myDate = df.parse( "02/20/2003" );
String strDate = df.format( myDate );

3. use java.util.Calendar to track a year back:
Calendar cal = Calendar.getInstance();
cal.add( Calendar.YEAR, -1 ); //go back one year;
Date aYearBack = cal.getTime();

3. to compare date:
if( joinDate.before( aYearBack ) ) {
   // get discount
} else {
   // no discount
}
0
 
girionisCommented:
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

- Split points between umangjoshi and kennethxu

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

girionis
EE Cleanup Volunteer
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now