troubleshooting Question

comparing timestamp help

Avatar of pothios
pothios asked on
9 Comments1 Solution266 ViewsLast Modified:
hello. im trying to compare 2 timestamp and then check if its pass 60 second. i tried out the following but it gave me a wrong result. did i do anything wrong?

/* inserting to database */
DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd hh:mm:ss");
java.util.Date date = new java.util.Date();
String sql = "insert into record values('" + userid + "', '" + status + "', ";
sql +="to_date('" + dateFormat.format(date) + "', 'YYYY/MM/DD HH:MI:SS'))";
/* retrieving from db */
String sql = "select max(time) as prevTime from record where user_id='" +userid+ "'";
Date recDate = mifa.getDate(sql); // returns a time stamp from oracle db
/* calculate the time */
java.util.Date now;
long diff;
now = new java.util.Date();
diff = now.getTime() - recDate.getTime(); // difference in milliseconds
diff = diff / 1000; // difference in seconds;
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 9 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 9 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros