Finding the average of a date

# Thread: Finding the average of a date

1. Senior Member
Join Date
Dec 1969
Posts
716

## Finding the average of a date

I am trying to track the span of when we receive inventory and when we ship the inventory. I want to find the average amount of time. i have this query that gives the average of EACH shipment (145 total), but I want an average of the total shipments. This is the query I use....<BR>select <BR>dateadd(hour,(datediff(hour,pat_entrada,pat_sa lida)/2),pat_entrada) ,<BR>pat_entrada, --date arrive<BR>pat_salida --date exit<BR>from tb_003dpatio<BR><BR>any thoughts from the experts?

2. Jeremy_D Guest

## RE: Finding the average of a date

Try this:<BR><BR>SELECT Cast(<BR> (<BR> AVG(Cast(pat_salida AS double precision)) +<BR> AVG(Cast(pat_entrada AS double precision))<BR> ) / 2.0 AS datetime)<BR> FROM tb_003dpatio<BR><BR>Trick is in casting the dates to a double precision (float(53)) first so you can perform an AVG calculation on it. The function operates on the basis that the avarage difference between some pairs of numbers (or dates) is the same as the difference between the avarage of all the first numbers and the avarage of all the last numbers. I think this will only work if there are no nulls in pat_entrada and pat_salida.<BR><BR>

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•