Date problem

1. Senior Member
Join Date
Dec 1969
Posts
176

## Date problem

I have a auctions table in SQL Server. Each row has a start date/time and an end date/time. From these fields I need to calculate the exact number of days,months,minutes and seconds between them, in this format 5 Days, 4 Hours,3 Mins,45 secs<BR>I can get the number of days using datediff, but how do I calculate the hours,mins and seconds (datediff will only calculate the total, for example total minutes between the two dates).<BR>Could someone point me any resources that could slove this problem, I can&#039;t find any.<BR><BR>Thanks<BR>Darren<BR>

2. Senior Member
Join Date
Dec 1969
Posts
404

## RE: Date problem

Select <BR>DateDiff(d,@startDate,@endDate) + &#039; Days, &#039; <BR>+ DateDiff(hh,@startDate,@endDate) + &#039; Hours, &#039; <BR>+ DateDiff(n,@startDate,@endDate) + &#039; Minutes, &#039; <BR>+ DateDiff(s,@startDate,@endDate) + &#039; Seconds&#039; <BR>AS TimeRemaining

3. Senior Member
Join Date
Dec 1969
Posts
404

## Maybe not, let me think

On second thought, that may not do it. Give me a sec.

4. Senior Member
Join Date
Dec 1969
Posts
404

## RE: Maybe not, let me think

Function TimeRemaining(lSeconds)<BR><BR>days = lseconds86400<BR>lSeconds = lSeconds mod 86400<BR>hours = lSeconds3600<BR>lSeconds = lSeconds mod 3600<BR>mins = lSeconds60<BR>lSeconds = lSeconds mod 60<BR><BR>TimeRemaining = days & " Days, " & hours & " Hours, " & mins & " Minutes, " & lSeconds & " Seconds"<BR><BR>End Function

5. Senior Member
Join Date
Dec 1969
Posts
176