Click here to Skip to main content
15,890,438 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hai,

I need to get difference of two datetime, and that diff value is set in next column.
like


Date	                 Duration
 28-02-2017 17:46:00	 
 28-02-2017 17:47:00	 00:01:00
 28-02-2017 17:49:00	 00:02:00
 28-02-2017 17:55:00	 00:06:00
Total            	 00:09:00


What I have tried:

SQL
select t.start_time ,datediff(t.start_time,t1.start_time) durarion  
From ICC_resource_utilization t
inner join ICC_resource_utilization t1 on t.utilization_id=t1.utilization_id
Posted
Updated 28-Feb-17 3:25am
v2
Comments
PIEBALDconsult 28-Feb-17 8:49am    
You may need a Common Table Expression.
Nataraj Pandiyan 28-Feb-17 12:06pm    
can u please explain

This is SQL Server version:
DECLARE @startdate datetime2 = '2007-05-05 12:10:09.3312722';  
DECLARE @enddate datetime2 = '2007-05-04 12:10:09.3312722';   
SELECT DATEDIFF(day, @startdate, @enddate);  

This is MySQL version:
SELECT 
    orderNumber,
    ROUND(DATEDIFF(requiredDate, orderDate) / 7, 2), --Calculate by Week 
    ROUND(DATEDIFF(requiredDate, orderDate) / 30,2) --Calculate by Month
FROM
    orders
 
Share this answer
 
Comments
CHill60 28-Feb-17 9:17am    
I'm not convinced that this does anything like the OP requirement
Nataraj Pandiyan 28-Feb-17 12:05pm    
This is not i exept
Try the solutions presented on this post - sql - MySQL - Subtracting value from previous row, group by[^]

stead of using c.value - prev.value as per the example use DATEDIFF(c.datevalue, prev.datevalue).

You will probably have to do a join to a subquery to get the total.
 
Share this answer
 
v2
Comments
Nataraj Pandiyan 28-Feb-17 12:04pm    
this link is very helpful for me.But need difference of two date.
CHill60 28-Feb-17 12:45pm    
I have updated my solution

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900