473,416 Members | 1,924 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,416 software developers and data experts.

How to calculate difference between old date/time captured in mysql and present date

Dear Sir,

I want to get the difference of date/time captured in mysql and present date/time in jsp.
I am using the following code to get, but its getting difference only in hrs, i used split strings in jsp for that, can u please help me in this code, i have to get difference in min and sec also.
Expand|Select|Wrap|Line Numbers
  1. <%@ page  import="java.sql.*,java.text.SimpleDateFormat" %>
  2.  
  3. <%! int x; %>
  4.  
  5. <%
  6.  
  7. String EmployeeId;// = request.getParameter("EmployeeId");
  8. EmployeeId = session.getAttribute("ssnEmployeeId").toString();
  9.  
  10. x = 0;
  11.  
  12.  
  13. Class.forName("com.mysql.jdbc.Driver").newInstance();
  14. Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/aams","root","root");
  15. Statement st = conn.createStatement();
  16. ResultSet rs = st.executeQuery("select employeename from admin where employeeid='"+EmployeeId+"' and flag = 0");
  17.  
  18. if(rs.next()){
  19.    //String employeeid=(String) session.getAttribute("employeeid");
  20.  
  21.     //if(employeeid.equals(employeeid) == true ){
  22.  
  23.    //  session.setAttribute("employeeid",employeeid);
  24.  
  25. //System.out.println("Reached");
  26.     rs = st.executeQuery("select intime from admin where employeeid = '"+ EmployeeId+ "' and flag = 0 ");
  27.     rs.next();
  28.  
  29.      java.util.Date now = new java.util.Date();
  30.       String DATE_FORMAT = "dd-hh";
  31.       SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT);
  32.  
  33.     String strDateNew = sdf.format(now) ;
  34.  
  35.  
  36.  
  37. String s3 = rs.getString(1);
  38.       String [] temp = null;
  39.       temp = s3.split("-");
  40.  
  41.  
  42. String strDate = temp[2], strTime = temp[3];
  43. //System.err.println("Reached");
  44.  
  45.       s3 = strDateNew;
  46.       temp = null;
  47.       temp = s3.split("-");
  48.       int curtime, oldtime;
  49.       curtime = Integer.parseInt(temp[1]);
  50.       oldtime = Integer.parseInt(strTime);
  51.  
  52.       System.out.println("Current Time" + curtime);
  53.       System.out.println("Old Time" + oldtime);
  54.       System.out.println("Current Date" + strDate);
  55.  
  56.       if(curtime<oldtime)
  57.           {
  58.           curtime=curtime+12;
  59.           }
  60.  
  61.  
  62.       int diff = curtime - oldtime;
  63.  
  64.       if(strDate.equals(temp[0]) == false || diff >=8)
  65.           {
  66.     %>
  67. <jsp:forward page="checkout.jsp" />
  68.     <%
  69.     }
  70.       else{
  71.           int total=diff;
  72.           diff = 8-diff;
  73.           session.setAttribute("ssnTimeDifference", diff);
  74.           session.setAttribute("totaltime", total);
  75.           response.sendRedirect("warning.jsp");
  76.           }
  77. }
  78. else{
  79.     %>
  80.  
  81.     <jsp:forward page="CheckIn.jsp" />
  82.     <%
  83. }
  84.  
  85. %>
Please help me in this code to get both min and sec...
Sep 3 '10 #1
0 1728

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: zaceti | last post by:
I'm new to MySQL and I am having a problem selecting the highest valued date/time for a particular day. Here is the table structure: ...
5
by: Gord | last post by:
Many scripts and calendars call client side system time in order to make presentations. However, the client's time may be improperly set, if set at all, and/or the relevant time may be from...
2
by: Noozer | last post by:
I have a textbox on one of my forms that is used to accept a time from the user. I need to write this value to a database to trigger an event later on. What I'd like to know is... Are there...
0
by: Chris | last post by:
Can someone point me the right way? I'm trying to use the date/time extensions but with little luck. Here's what I've got: <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0"...
2
by: mcmcalex | last post by:
is there an easy way to make a date/time field (in Access) convert to a date field (in Excel) when using ms-query? I'm pretty good with xl, but new to access, so apologies if this is covered on p1...
0
by: Miguel Dias Moura | last post by:
Hello, i am just finishing a web site in ASP.net / VB using Dreamweaver MX 2004 and in all the pages i use the date/time format as follows: Date: DD-MM-YYYY Time: HH-MM (24 hours) Anyway,...
4
by: Miguel Dias Moura | last post by:
Hello, i am just finishing a web site in ASP.net / VB using Dreamweaver MX 2004 and in all the pages i use the date/time format as follows: Date: DD-MM-YYYY Time: HH-MM (24 hours) Anyway,...
11
by: walterbyrd | last post by:
My MySQL table has a field that is set as type "date." I need to get today's date, and insert it into that field. The default for that MySQL field is 2006-00-00. I know about the date()...
7
by: orajat | last post by:
hi, how do i calculate difference in time in seconds (00:09:05 - 00:09:00 = 300) where start time being a field and the difference in time is calculated in AHT field, ie last record minus previous...
13
by: dizzydangler | last post by:
Just a quick question...I'm running an MS Access 2007 db that tracks appointments in a single table. Date and time are entered as separate fields in short date (mm/dd/yyyy) and short time (hh:mm)...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.