• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 362
  • Last Modified:

How can i calculate time diff in sec between to dates

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
AlexPonnath
Asked:
AlexPonnath
  • 2
  • 2
  • 2
  • +1
4 Solutions
 
Vitor MontalvãoMSSQL Senior EngineerCommented:
SELECT datediff(ss, stattime, endtime)  FROM YourTable
0
 
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
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
 
Vitor MontalvãoMSSQL Senior EngineerCommented:
Sorry, I meant:

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

Or:

SELECT datediff(second, stattime, endtime)  FROM YourTable
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
ibostCommented:
select DATEDIFF(ss, starttime, endtime)

the ss means seconds.

YOu can look up DATEDIFF in books online for more details.
0
 
peyoxCommented:
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
 
peyoxCommented:
Woooow, you guys are fast :)
When I started writing this post, there was no answers :)
0
 
ibostCommented:
same for me ;)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

  • 2
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now