Solved

# How can i calculate time diff in sec between to dates

Posted on 2005-04-06
336 Views
I have a table which stores a field stattime and a endtime both are date/time  fields and i need to be able to tell the diff in sec.
How can i do that...

0
Question by:AlexPonnath

LVL 44

Expert Comment

SELECT datediff(ss, stattime, endtime)  FROM YourTable
0

LVL 65

Assisted Solution

Try this...

=CLng(([DateField1] - [DateField2]) * 86400)

Each day is 1, and everything below that is in the decimal value.  There are 86,400 seconds in a day.

Hope this helps.
-Jim
0

LVL 44

Accepted Solution

Sorry, I meant:

SELECT datediff('ss', stattime, endtime)  FROM YourTable

Or:

SELECT datediff(second, stattime, endtime)  FROM YourTable
0

LVL 10

Assisted Solution

select DATEDIFF(ss, starttime, endtime)

the ss means seconds.

YOu can look up DATEDIFF in books online for more details.
0

LVL 6

Assisted Solution

select DATEDIFF(second, dateA, dateB);

example:
select DATEDIFF(second, '2005-04-12 14:43:17','2005-04-12 14:43:13');

first parameter: second means - calculate result in seconds

datediff calculates: dateB-dateA, so it can be negative.
0

LVL 6

Expert Comment

Woooow, you guys are fast :)
When I started writing this post, there was no answers :)
0

LVL 10

Expert Comment

same for me ;)
0

## Featured Post

### Suggested Solutions

In this article—a derivative of my DaytaBase.org blog post (http://daytabase.org/2011/06/18/what-week-is-it/)—I will explore a few different perspectives on which week today's date falls within using Microsoft SQL Server. First, to frame this stu…
Introduced in Microsoft SQL Server 2005, the Copy Database Wizard (http://msdn.microsoft.com/en-us/library/ms188664.aspx) is useful in copying databases and associated objects between SQL instances; therefore, it is a good migration and upgrade tool…
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.