473,326 Members | 2,081 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,326 software developers and data experts.

How to find the difference between two timestamp column

please Solve my issue,
I have Table name Record which has the following columns,
Empid in number column, dat in timestamp
which has the following values
Expand|Select|Wrap|Line Numbers
  1. empid                            dat
  2. ======                         ====
  3. 101                              4/9/2012 9:48:54 AM
  4. 101                               4/9/2012 9:36:28 AM
  5. 101                                4/9/2012 6:16:28 PM
  6. 101                                4/10/2012 9:33:48 AM
  7. 101                                4/10/2012 12:36:28 PM
  8. 101                                4/10/2012 8:36:12 PM
  9. 101                                4/11/2012 9:36:28 AM
  10. 101                                4/11/2012 4:36:22 PM
Here I need to display the following columns,

empid,min(dat) as start,max(dat) as end and difference(max(dat)-min(dat) for each day,
Here 3 different days are exists so It should return 3 records with the above mentioned columns,
Please Help me to get this.

Thank you,
Regards,
Gurujothi
Apr 25 '12 #1

✓ answered by Gurujothi D

Hi Rabbit,
this code solved my issue,
Expand|Select|Wrap|Line Numbers
  1. select empid,trunc(dt) as Dat, 
  2. to_char(min(dt),'hh:mi am') as Firstintime, 
  3. to_char(max(dt),'hh:mi am') as Lastouttime, 
  4. to_char(trunc(sysdate) + (max(dt) - min(dt)),'hh24:mi') as TotalHours 
  5. from trans 
  6. group by trunc(dt),empid
Thank you,
regards,
gurujothi

5 7228
Rabbit
12,516 Expert Mod 8TB
Do just that in an aggregate query. Just group by the empid, year, month, and day of the date.
Apr 25 '12 #2
Hi Rabbit,
Thank you for your response,can you post the query here.?
Apr 26 '12 #3
Rabbit
12,516 Expert Mod 8TB
I do not give out code unless the poster has shown they have attempted the solution themselves.
Apr 26 '12 #4
Hi Rabbit,
If I use the following query am getting the output,

Expand|Select|Wrap|Line Numbers
  1. select empid,trunc(dt) as Dat,
  2. min(dt) as Firstintime,
  3. max(dt) as Lastouttime,
  4. to_number(max(dt) - min(dt))*24 as TotalHours 
  5. from trans
  6. group by trunc(dt),empid
For firstintime it displaying output as 3/29/2012 9:12:57 AM but I need only 9:12:57 AM for this column,

For lasttintime it displaying output as 3/29/2012 9:24:24 PM but I need only 9:24:24 PM for this column,

For Totalhours it displaying output as 12.1908333333333 but I need only in hour and minute format i.e 9.12 for this column

How to get this output format?

regards,
gurujothi
Apr 26 '12 #5
Hi Rabbit,
this code solved my issue,
Expand|Select|Wrap|Line Numbers
  1. select empid,trunc(dt) as Dat, 
  2. to_char(min(dt),'hh:mi am') as Firstintime, 
  3. to_char(max(dt),'hh:mi am') as Lastouttime, 
  4. to_char(trunc(sysdate) + (max(dt) - min(dt)),'hh24:mi') as TotalHours 
  5. from trans 
  6. group by trunc(dt),empid
Thank you,
regards,
gurujothi
Apr 26 '12 #6

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

Similar topics

2
by: AzGhanv/. | last post by:
Hi, I m searching for some Script / Function ... to find difference in data b/w 2 similar tables (exactly same fields structure) in sql 2000. plz update me asap ! thanks in advance !
1
by: gnuoytr | last post by:
i can't find either confirmation or contradiction in the docs available. a colleague asserts that a column defined TIMESTAMP is always and automatically updated when any column in the row is...
1
by: Marcus Leon | last post by:
Access freezes when we attempt to link to and then open an Oracle table that has a Timestamp column. Does anyone know why? This issue does not occur if you attempt to link to and open a table...
1
by: Prafull Soni | last post by:
hi Can anyone give me program to find difference between two dates? thanks Prafull Soni
5
by: Ali Baba | last post by:
Hi, Is there is equivalent of VB's DateDiff() method in C#. I need to find difference in months between two dates that are years apart. Docs says that I can use TimeSpan like: TimeSpam ts =...
22
by: Mal Ball | last post by:
I hope I have the right forum for this question. I have an existing Windows application which uses a SQL Server database and stored procedures. I am now developing a web application to use the same...
5
by: Konstantinos Pachopoulos | last post by:
Hi, does any body now any such algorith? to find difference in days from YYYYMMDD to YYYYMMDD? Or just an algorithm, that converts YYYYMMDD to seconds since the epoch? Thanks
2
by: manishamca | last post by:
can anyone say me how to find the difference of values present in two textbox and display the result in the third textbox. for eg: <input type=text name=t1 value=123> <input...
1
by: Frank Swarbrick | last post by:
We're trying to take advantage of the new ROW CHANGE TIMESTAMP option. Here is a simple table: CREATE TABLE "ACCTASGN"."NUMBER_STATUS" ( "STATUS_CODE" CHAR(1) NOT NULL , "STATUS_DESCRIPTION"...
0
by: db2dbdba | last post by:
How can I find time/timestamp of instance creation on DB2 LUW? I thought I might find this info on dbm snapshot but no luck. it gives only the information on last start time of instance ? I...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.