473,796 Members | 2,629 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

3 New Member
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 1746

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

Similar topics

2
4719
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: +--------------+-----------------+-----+----+--------+--------------+ | Field | Type | Null| Key| Default|Extra | +--------------+-----------------+-----+----+--------+--------------+ | id | int(10) unsigned| | PRI| NULL |auto_increment| | timestamp | datetime ...
5
2311
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 another time zone. It would be of great value if the time of some central source could be drawn, in the form of a ".js" file, into the script to avoid dependence on the client's date/time.
2
2508
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 any functions in javascript that can convert different time formats to a known format (24 hour clock)... 5pm -> 17:00 or 5:00 to 05:00, etc. ??? Assuming that I get the input into a 24 hour format, how can I create a full
0
1541
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" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:date="http://exslt.org/dates-and-times" > <xsl:template match="/" > date-time: <xsl:value-of select="date:date-time()"/>
2
1659
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 of the user's guide (my _quick_ search in this forum didn't find an answer to my question). tia mcalex
0
267
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, everything works fine when testing in my computer. However, when i uploaded the web site to my hosting space in the date/time appears as
4
2788
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, everything works fine when testing in my computer. However, when i uploaded the web site to my hosting space in the date/time appears as
11
21079
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() function. I have tried date("Y-m-d") and date("U"), neither worked. The date field was just filed with all zeros. Can anybody point me in the right direction?
7
12050
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 record. this should be a continious excercise in ms access database table
13
19973
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) format. I've been running queries by date alone, which has been working, but there are times when I have to run queries based on times as well. (e.g. return all apointments that occurred after 1:00 PM on 12/15/2009 and before 1:00 PM on 12/22/2009). ...
0
9679
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9527
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10453
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10172
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10003
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9050
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7546
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5441
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3730
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.