How to calculate the difference between 2 different times being input.
import java.io.*;
import java.util.*;
public class ClockingInOut
public static void main(String[] args) throws IOException
BufferedReader keyboard = new BufferedReader (new InputStreamReader (System.in));
String input, input1, input2;
int num1, num2, answer;
System.out.println ("\t\t\tEMPLOYEE CLOCKING IN AND OUT SYSTEM!");
do
System.out.print ("\nWould you like to clock in and out? yes (y), no(n), ?: ");
input = keyboard.readLine();
if (input.equals("y"))
System.out.print ("Please enter the hours you clocked in: ");
num1 = Integer.parseInt (input1 = keyboard.readLine());
System.out.print ("Please enter the minutes you clocked in: ");
num2 = Integer.parseInt (input2 = keyboard.readLine());
System.out.print ("Now Please enter the hours you clocked out! ");
num1 = Integer.parseInt (input1 = keyboard.readLine());
System.out.print ("And please enter the minutes you clocked out!: ");
num2 = Integer.parseInt (input2 = keyboard.readLine());
Hi people, i think my coding may be wrong. I would like the user to input the hours and then minutes of the time they clocked in and out of work. and then i want the program to be able to calculate the hours worked and print the mesage in the Command Prompt window.
It's really confusing and hard, please help and provide me with the correct soure code if you can.
Also, like in html how the notepad file has to have the opening and closing brackets, does java coding have something like this.
Please reply. Thank You.
hi
check this java class
import java.sql.Time;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
public class util
public static void main(String[] args) throws Exception
long t1 = getTimeOnlyLong();
Thread.sleeo(2000);
long t2 = getTimeOnlyLong();
System.out.println(differenceBetween2Times(t1,t2));
public static long getTimeOnlyLong()
Date d = new Date();
return d.getTime();
public static String differenceBetween2Times(long l1 , long l2)
long diff = l1 - l2;
System.out.println("differ = " + diff);
Date d = new Date();
d.setTime(diff);
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
return sdf.format(d.getTime());
}
Similar Messages
-
Hi,
I am new to Labview. This question might be a joke to some of you here, but any help would be greatly appreciated. I have a spreadsheet with time stamps and power outputs from a generator. I am supposed to calculate the difference between consecutive time stamps, which will act as a delay for the next power output update that needs to be sent. For example, lets say that I have to following data:
Time Stamp Power Output
11:00:00 AM 3kW
11:00:02 AM 2.9kW
11:00:04 AM 3.2kW
11:00:06 AM 3.1kW
The above data doesn't make any sense, but it is just for the purpose of this question.
So, I have to read 11:00:00 AM and 3kW initially - 3kW is the initial request thatHello
you can simple subtract one time from the other one and so you get the difference. -> Example
Mike
Attachments:
Unbenannt 2.vi 8 KB -
Calculate the difference between two dates times in infopath form 2013
Hi,
I have an infopath 2013 form that contains three fields:
2 date time and the 3rd contains the difference between the two in hours
how I can make the difference between the two so that the display will be like this:
Date Time1 08/21/2014 22:00
Date Time2 08/22/2014 1:00
Diff Field 3:00Hi,
Please refer to the following article which matches your requirement exactly.
Calculate the difference between two date picker controls in InfoPath using rules and formulas - no code!
Please mark it answered, if your problem resolved. -
How to calculate the difference between intdate and getdate
Hi,
My requirement is to get the data for all the claims where the difference between transactiondate and getdate() should be less than or equal to 7 which means any claims that happened in the past week.
So, my query would be something like this
select * from claims
where transactiondate-getdate < 8
But my transactiondate is in int format such as 20150331 and getdate would be in the format of 2015-03-31. Can someone please help me on how can i achieve the difference between these 2 date formats in the where clause.
Please let me know if you have any questions or if i am unclear.
ThanksHi SqlDev12,
Please find the below condition in your query,hope it would help you
DATEDIFF(DD,CAST(CAST(TransactionDate
AS
VARCHAR)
AS
DATETIME),GETDATE())
< 8
Thanks & Regards,
Praveena. -
How to calculate the difference between values in a custom PSObject?
If I have a PSObject (created from an imported CSV) that has data like the following:
date,Total size of files uploaded
03-17-2014 09:08,1293334574547
03-17-2014 09:10,1293335326912
03-17-2014 09:13,1293336523562
03-17-2014 09:14,1293337541156
03-17-2014 09:16,1321031223511
03-17-2014 09:16,1321032156844
This CSV will have lines added to it, so the total number of lines will vary.
Is there a way that two most recently added values and calculate the difference of the "Total size of files uploaded" values?
I have the columns properly cast as datetime and
int64 already using this:
$csv = Import-Csv $csvLocation |
Where-Object { ![string]::IsNullOrWhiteSpace($_.datetime) } |
Foreach-Object {
$_.datetime = $_.datetime -as [datetime]
$_."Total size of files uploaded" = $_."Total size of files uploaded" -as [int64]
$_ }
I tried searching thinking surely there must be someone else who has tried to do this" but I cannot find anything. I am just not sure how to approach this problem. Any help would be appreciated!Assuming all of your records are sequential with the last two being the most recent you could use this:
$csv = Import-Csv $csvLocation |
Where-Object { ![string]::IsNullOrWhiteSpace($_.datetime) } | select -last 2
Foreach-Object {
$_.datetime = $_.datetime -as [datetime]
$_."Total size of files uploaded" = $_."Total size of files uploaded" -as [int64]
$_ }
$Difference = $csv[1]."Total size of files uploaded" - $csv[0]."Total size of files uploaded"
This uses the index of the imported array and just the last two records. Note that this will give a negative value if the total is less in the later record. Hope this helps!
You could also use
| sort datetime -ascending | select -last 2
if they aren't already in order... -
How to calculate the difference between two dates?
Hello,
I would like to write some code which figures out how many days are between the Date_of_change (which is of datatype DATE, length 7 and of format DD-MON-YY) and the current date today. Then if the difference between Date_of_change and the current date is greater that 30 days for example then I would like to delete that record from the database.
Thanks
DougSomething like this should work:
SQL> select * from emp order by hiredate ;
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
7934 MILLER CLERK 7782 21-OCT-2005 1300 10
7902 FORD ANALYST 7566 22-OCT-2005 3000 20
7900 JAMES CLERK 7698 23-OCT-2005 950 30
7876 ADAMS CLERK 7788 24-OCT-2005 1100 20
7844 TURNER SALESMAN 7698 25-OCT-2005 1500 0 30
7839 KING PRESIDENT 26-OCT-2005 5000 10
7788 SCOTT ANALYST 7566 27-OCT-2005 3000 20
7782 CLARK MANAGER 7839 28-OCT-2005 2450 10
7698 BLAKE MANAGER 7839 29-OCT-2005 2850 30
7654 MARTIN SALESMAN 7698 30-OCT-2005 1250 1400 30
7566 JONES MANAGER 7839 31-OCT-2005 2975 20
7521 WARD SALESMAN 7698 01-NOV-2005 1250 500 30
7499 ALLEN SALESMAN 7698 02-NOV-2005 1600 300 30
7369 SMITH CLERK 7902 03-NOV-2005 800 20
14 rows selected.
SQL> delete from emp where hiredate < sysdate - 30 ;
10 rows deleted.
SQL> select * from emp order by hiredate ;
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
7566 JONES MANAGER 7839 31-OCT-2005 2975 20
7521 WARD SALESMAN 7698 01-NOV-2005 1250 500 30
7499 ALLEN SALESMAN 7698 02-NOV-2005 1600 300 30
7369 SMITH CLERK 7902 03-NOV-2005 800 20
4 rows selected.
SQL> -
Calculate the Difference Between two dates excluding weekends and Holidays
Hi,
We need to calculate the difference between the two dates by excluding the Local public holidays (It is global and varies across countries) and weekends should not be included in calculation for a business day in OBIEE.
We have two dates: Open date and close date when ever close date is null we are calculating age based on taking the current timestamp and need to exclude the weekends and Holidays when ever the close date is null.
Ex:
Col1 col2 Total
11/9/2010 2:46:38 PM Null 13
11/2/2010 8:06:26 PM 11/3/2010 5:37:03 PM 1
(In the Total we shouldn't include the weekends,holidays)
Please let me know how to calculate the difference between two dates by excluding the weekends and holidays.
Thanks
Edited by: user10441472 on Nov 22, 2010 3:14 PMYou already asked this question and I answered it...
Re: calculation of Business day in OBIEE -
Calculate the Difference between 2 dates
Please let me know how to Calculate the Difference between 2 dates in Time Management. I have a hire date(U1) and adjusted Service Date(B2)
I need to Find out the number of Years, Days and Months between these 2 dates
Thanks a lot in AdvanceHi Rahul,
You can take a look at the standard function 'HR_HK_DIFF_BT_2_DATES' and see if it suits your need.
Regards.
Francis -
To calculate the difference between timings ( PM - AM )
Hi All,
Can anyone let me know how to calculate the difference between the time.
EG : From time : 23:00:00 pm
To time : 01:00:00 am
instead of 2 hours we are getting 22 Hrs
Thanks in Advance
SathyapriyaHi Priya,
How about using FM: HR_PDC_ADD_24_HOURS
PARAMETERS: p_tim1 TYPE uzeit, " 23:00:00
p_tim2 TYPE uzeit. " 01:00:00
DATA: l_diff TYPE uzeit.
START-OF-SELECTION.
IF p_tim1 > p_tim2.
CALL FUNCTION 'HR_PDC_ADD_24_HOURS'
CHANGING
logical_time = p_tim2.
ENDIF.
l_diff = p_tim2 - p_tim1.
WRITE:/ l_diff.
As you are saying you have 30 fields to calculate, make a subroutime instead of calculating everytimg like:
PERFORM cal_tim_diff USING p_tim1 p_tim2
CHANGING l_diff.
*& Form CAL_TIM_DIFF
FORM cal_tim_diff USING p_tim1 TYPE uzeit
p_tim2 TYPE uzeit
CHANGING p_diff TYPE uzeit.
IF p_tim1 > p_tim2.
CALL FUNCTION 'HR_PDC_ADD_24_HOURS'
CHANGING
logical_time = p_tim2.
ENDIF.
p_diff = p_tim2 - p_tim1.
ENDFORM. " CAL_TIM_DIFF
If it still doesnt help, check the data type of the time fields that you are considering. -
Hi,
I am new to Labview. This question might be a joke to some of you here, but any help would be greatly appreciated. I have a spreadsheet with time stamps and power outputs from a generator. I am supposed to calculate the difference between consecutive time stamps, which will act as a delay for the next power output update that needs to be sent. For example, lets say that I have to following data:
Time Stamp Power Output
11:00:00 AM 3kW
11:00:02 AM 2.9kW
11:00:04 AM 3.2kW
11:00:06 AM 3.1kW
The above data doesn't make any sense, but it is just for the purpose of this question.
So, I have to read 11:00:00 AM and 3kW initially - 3kW is the initial request that is sent. Then I have toRepeated forum post
Please view http://forums.ni.com/ni/board/message?board.id=170&message.id=294435
Regards,
Juan Galindo
Applications Engineer
National Instruments -
Calculate the difference between Creation date and key date
Hello
I want to calculate the difference between creation date of the document with key date(todays date). How can i do that in the query designer. Also then I want to restrict my key figure on this difference if it is =10..please can someone suggest what can be done
thanksHi Grame...
For the days calculation ..
I suggest you to use replacement path ..
I have the reference that you can see the sample. The case of samples is also about day calculation.
http://www.sd-solutions.com/documents/SDS_BW_Replacement%20Path%20Variables.html
Hopefully it can help you a lot.
Regards,
Niel. -
How to calculate the difference of two totals which are of the same group?
Post Author: mingli
CA Forum: Formula
Hello,
I have an existing report which has a group defined. The group generates two set of data, at the footer of each set of data, the total is calcuated. Now I need to calculate the difference between the totals. For example:
value
set 1
item 1 100
item 2 200
item 3 300
set 1 total 600
set 2
item 1 200
item 2 20
item 3 300
item 4 40
set 2 total 560
difference 40
My question is: how can I do this? I'm thinking about create a formula. But the problem is, these two totals have the same field name. Could someone help me out?
Thanks.Post Author: deejayw
CA Forum: Formula
Hi,I have a similar type of query...my Sets only ever contain two entries but there is an unknown number of sets. value
set 1
item 1 100
item 2 200
difference (item2 - item1) = 100
set 2
item 1 200
item 2 20difference (item2 - item1) = -180
Set 3, Set 4, etc, etc I need to figure out how to calculate the "difference (item2 - item1)" total above. I am really confused by this and need assistance. Many thanks. -
Calculate the difference between two dates
I would like to calculate the difference between two dates in PL/SQL and return the result as a number of days expressed as an integer value.
Denes,
A fair point, I should really have posted this on the SQL forum (I'm new to the forum as well as PL/SQL) but thanks for responding anyway. It does raise a question as to how to implement this in ApEx though.
I have created the function and am calling it as shown below from the source window of a form. The source type is 'PL/SQL expression or function' and the expression in the source window of the form is:
calc_date_difference (:p26_c_payment, :p26_c_rec)
The two parameters being passed are of type date but I'm not sure how to handle the ruturned number and populate the form in ApEx with this value.
Is it possible to do it this way or am I taking completely the wrong approach?
Regards
Sandy
This is not ApEx related but SQL related:
CREATE OR REPLACE FUNCTION calc_date_difference (
p_date_1 VARCHAR2,
p_date_2 VARCHAR2
RETURN NUMBER
v_difference NUMBER;
v_sql_err VARCHAR2 (4000);
BEGIN
v_difference := TRUNC (TO_DATE (p_date_1)) - TRUNC
(TO_DATE (p_date_2));
RETURN v_difference;
CEPTION
WHEN OTHERS
THEN
v_sql_err := SQLERRM || CHR (10) || CHR (10) ||
SQLCODE;
ND calc_date_difference;and
SQL> SELECT calc_date_difference ('23.01.2007',
'20.01.2007') diff
2 FROM DUAL;
DIFF
3
Denes Kubicek -
How to get the difference between two columns in a column group
Hi All,
My first time here and really new to programming. I would like to get the difference between 2 columns that are inside
a column group.
Here is my sample table below: The Column Group is PeriodNumber and can only choose 2. like 1 and 2.. I would like to have a third row which will simply calculate the difference between the amounts in PeriodNumber 1 and 2.
PeriodNumber
Account 1 2
1) Cash 10,000 15,000
2) Receivables 12,000 11,500
3) Equipment 5,000 5,500
Total Assets 27,000 32,000Hi yabgestopa,
From your description, you want to get the difference between two columns in a column group. After testing it in my environment, we can use custom code to achieve your requirement. For more details, you can refer to the following steps:
Copy the custom code below and paste it to your report. (Right-click report>Report Properties>Code)
Dim Shared Num1 As Integer
Dim shared Num2 As Integer
Public Function GetAmount(Amount as Integer, Type as String)
If Type = "1" Then
Num1=Amount
Else
Num2=Amount
End If
Return Amount
End Function
Public Function GetDif()
Return Num1-Num2
End function
Right-click the second column to insert a third column with Outside Group-Right.
Then use the expressions below in the matrix.
=Code.GetAmount(Fields!Amount.Value,Fields!PeriodNumber.Value)
=code.GetAmount(Sum(Fields!Amount.Value),Fields!PeriodNumber.Value)
=Code.GetDif()
The report looks like below.
If you have any questions, please feel free to ask.
Thanks,
Katherine Xiong
Katherine Xiong
TechNet Community Support -
How to find the difference between Project costs & Cost center costs?
Hi all,
Can you please explain me ? What is project Cost & Cost center cost and which are the tables having those fields of project cost & cost center Costs? And how to find the difference between their costs ? And please give me the functional Idea about it?
Thanking you all in Advance...
Regards,
ChandruHi,
goto table COSP:
1) object-no. beginning with 'KS' refer to cost-centre
example: 'KSKOKA4711'
with KS, KOKA = controlling area and 4711 = cost centre
2) OBJNR beginning with 'PR' refer to projects / WBS-element
example PR00001234
Message was edited by: Andreas Mann
Maybe you are looking for
-
{file} is used by Mac OS X and can't be opened
This file is a video file and the lock that OS X has on it is persistent between reboots. Anyone know how to get OS X to let go of the file and let me watch it please? Thanks
-
I can download a program but wont instal
I downloaded a free trail of a DJ software i am thinking of buying, but after i downloaded it, i click to open and it said i couldn't install because its says this program can not be run is DOS mode. Can someone help me? Im on my first mac and am abs
-
Hi, does anybody know the ETA for Oracle 10g R2? I have to set up a new Oracle database on Red Hat Enterprise Linux 3 ES. I would like to use Oracle 10g, but I am not sure if the current release (R1) is good enough for production use: maybe Oracle 9i
-
Is this possible in oracle?
Hi guys, i was just curious whether this is possible to display in oracle like C? situation is like. I have to code like, it should ask user to enter the number. and then it should display the result on screen like this. e.g. if user enters 3 then it
-
Waveform with time stamps randomly separated
Folks, I'd like to get your advice on the following task. A spectrometer takes data at arbitrary, not foreseeable instants. To each new point a time stamp is attached. The data shall be displayed in a waveform graph with the data coordinate on the y-