Difference of two date time in sql server

0 votes

Is there a method to use SQL Server to calculate the difference between two datetimes?

For example, my dates are

  1. 2010-01-22 15:29:55.090
  2. 2010-01-22 15:30:09.153

So, the result should be 14.063 seconds. Can someone please help me get this output?

Aug 26, 2022 in Database by Kithuzzz
• 38,000 points
697 views

1 answer to this question.

0 votes

Just a note of caution with DateDiff: if you are trying to get a specific timespan, difficulties may arise because it counts the number of times you exceed the boundary you define as your units. e.g.

select datediff (m, '20100131', '20100201')

Returns a result of 1 since it crossed the barrier from January to February; hence, datediff would return a value of 1 even though the span is 2 days because it crossed one date boundary.

select datediff(mi, '2010-01-22 15:29:55.090' , '2010-01-22 15:30:09.153')

Gives a value of 1, indicating that it once crossed the minute barrier. Despite being approximately 14 seconds long, this value would be reported as one minute if the units were minutes.

I hope this helps you.

answered Aug 27, 2022 by narikkadan
• 63,600 points

edited Mar 5

Related Questions In Database

0 votes
1 answer

Calculate time difference in minutes in SQL Server

SELECT  Diff = CASE DATEDIFF(HOUR, StartTime, EndTime)                     WHEN ...READ MORE

answered Oct 4, 2022 in Database by anonymous

edited Mar 5 1,359 views
0 votes
1 answer

Syntax of for-loop in SQL Server

TSQL has no for-loop, we have only ...READ MORE

answered Feb 15, 2022 in Database by Neha
• 9,020 points
1,018 views
0 votes
1 answer

Convert Date format into DD/MMM/YYYY format in SQL Server

Using convert() and style 106, you can ...READ MORE

answered Feb 23, 2022 in Database by Vaani
• 7,070 points
14,621 views
0 votes
0 answers

What's the difference between a temp table and table variable in SQL Server?

We can build temp tables in SQL ...READ MORE

Feb 25, 2022 in Database by Vaani
• 7,070 points
722 views
0 votes
1 answer

How Can I use "Date" Datatype in sql server?

There's problem in all of them and ...READ MORE

answered Feb 9, 2022 in Database by Neha
• 9,020 points
1,505 views
0 votes
1 answer

Difference between datetime and timestamp in sqlserver?

Timestamp is a synonym for rowversion, according ...READ MORE

answered Feb 16, 2022 in Database by Vaani
• 7,070 points
5,180 views
0 votes
1 answer

How to convert DateTime to VarChar

With Microsoft Sql Server: -- -- Create test case -- DECLARE ...READ MORE

answered Feb 23, 2022 in Database by Neha
• 9,020 points
1,354 views
0 votes
1 answer

How Can I use "Date" Datatype in sql server?

Your dates are interpreted as MM-DD-YYYY. This ...READ MORE

answered Jun 21, 2022 in Others by nisha
• 2,210 points
713 views
0 votes
0 answers

What is the difference between drop table and delete table in SQL Server?

What is the distinction between the following ...READ MORE

Aug 9, 2022 in Database by Kithuzzz
• 38,000 points
1,046 views
0 votes
0 answers

Convert date from dd-mm-yyyy to yyyy-mm-dd in SQL Server

Given date: DECLARE @Date1 VARCHAR(50) = '30-01-2015' I want ...READ MORE

Aug 18, 2022 in Database by Kithuzzz
• 38,000 points
6,421 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP