[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 355
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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