Click here to Skip to main content
15,880,469 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have one table with datetime is a one column....i create a hotel application ,Now i need,if user order 1 item.
C#
orderid   tableid   Timetaken(Mins)   itemname        datetime  
   1        1           10              Pizza    2013-06-20 05:30:33.343 PM  

then after 5 minutes ,i add another One item.
C#
orderid   tableid   Timetaken(Mins)   itemname        datetime  
   1        1           10              Burger    2013-06-20 05:35:33.343 PM

Now,i find the timedifference between two item....using Sql Query...Timedifference=5mins and timetodelivery is 15mins(Reduce the 5 mins because this is waiting time)....
After,3 mins i add another one item
C#
orderid   tableid   Timetaken(Mins)   itemname        datetime  
   1        1           10              Burger    2013-06-20 05:38:33.343 PM

Now,the waiting time is 3mins....
Totaltime=30mins
TimeDiffernece={item1 to item2 is 5mins and item2 to item3 is 3mins}==>8mins
Now,the timetodelivery=30mins-8mins=22mins
How i find out the Timedifference between three items......Please Advance thanks...
Posted

1 solution

Create test data
SQL
create table orders (orderid int,tableid int,orderpart int,timetaken int,itemname varchar(50),datetimeentered datetime);
insert into orders values (1,1,1,10,'Pizza','2013-06-20 05:30:33:343 PM');
insert into orders values (1,1,1,10,'Burger','2013-06-20 05:35:33:343 PM');
insert into orders values (1,1,1,10,'Burger','2013-06-20 05:38:33:343 PM');
insert into orders values (1,1,2,20,'Dhosa','2013-06-20 06:03:33:343 PM');
insert into orders values (1,1,2,10,'Juize','2013-06-20 06:03:33:343 PM');


Run the queries
SQL
select datediff(minute,
    min(datetimeentered),
    max(datetimeentered)
    ) As TimeDifferenceInMinutes from orders t1 where orderid=1 and tableid=1 and orderpart=1
 
select datediff(minute,
    min(datetimeentered),
    max(datetimeentered) 
    ) As TimeDifferenceInMinutes from orders t1 where orderid=1 and tableid=1 and orderpart=2


Results
TimeDifferenceInMinutes
8
TimeDifferenceInMinutes
0
 
Share this answer
 
v7
Comments
sarathtamil 20-Jun-13 9:22am    
Thank u sir....
sarathtamil 21-Jun-13 7:18am    
Then,I find the time difference,,,But after 22 mins completed and extra 3 mins completed ...then i add another two item

orderid tableid Timetaken(Mins) itemname datetime
1 1 20 Dhosa 2013-06-20 06:03:33.343 PM
1 1 10 Juize 2013-06-20 06:03:33.343 PM
How to find the Current time taken in two items(30mins)??Advance thanks.....
Mike Meinz 21-Jun-13 7:44am    
I updated Solution 1. I used the same query. If this is not correct, then I do not understand your business requirement and you will have to do a more thorough job of explaining exactly how the time difference should be calculated.
sarathtamil 21-Jun-13 7:47am    
i need a time to delivery that items....
Mike Meinz 21-Jun-13 7:52am    
You will have to do a better job of describing exactly what you want. You are assuming I understand your terms. When you use terms like "time to delivery", you need to specify the algorithm in words that describe how "time to delivery" is computed. If you are unable to do that, then you need to ask the person that gave you this assignment to do that.

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