Quantcast
Channel: CodeSection,代码区,SQL Server(mssql)数据库 技术分享 - CodeSec
Viewing all articles
Browse latest Browse all 3160

How DATEDIFF_BIG a new feature of SQL SERVER 2016 Can Keep You Out of Trouble

$
0
0

How DATEDIFF_BIG a new feature of SQL SERVER 2016 Can Keep You Out of Trouble
Rajat Jaiswal-337252

I am Rajat Jaiswal. I have around 9 years of industry experience. I have always found technology and programming to be very interesting and for me, programming is not something that ends when I step out of the office. I love exploring new stuff and databases amuse me the most. I started blogging in 2006 on http://rajatjaiswal.blogspot.com and http://indiandotnet.wordpress.com, http://sqlRaaga.blogspot.com I am quite active on my blogs and often post entries on Microsoft technologies like C#, ASP.NET, SQL Server, Silverlight & windows Phone 7.

How DATEDIFF_BIG a new feature of SQL SERVER 2016 Can Keep You Out of Trouble Posted on 22 October 2016 Comments

In the series of SQL SERVER 2016, this is a new post. in this post, we will discuss DATEDIFF_BIG and how it is helpful.

So, before jumping into directly in technical details, we all know that time is very important and every second valuable and countable but sometimes every microsecond & nanosecond is also countable. For such operations in which every microsecond & nanosecond is countable, we can use DATEDIFF_BIG function.

As you aware the BIGINT range is from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807. Here if any difference (Micro & Nano) second is out of the the mentioned range then DATEDIFF returns that value else return error (Obviously).

Below is the basic syntax if DATEDIFF_BIG although it is similar to DATEDIFF. We can say it is a extended version of DATEDIFF.

DATEDIFF_BIG( datePart, start Date, End date)

The value of datePart is same like DATEDIFF function.

For example if you want to collect millisecond difference then use ms , microsecond then mcs and for nanosecond ns.

As per the MSDN for the Millisecond, the maximum difference between start date & end date is 24 days, 20 hours, 21 minutes and 23,647 seconds. For Second, the maximum difference is 68 years.

Now, let see why this DATEDIFF_BIG introduced so, I am running a DATEDIFF function in SQL SERVER 2012 and see what we get after running that query.


How DATEDIFF_BIG a new feature of SQL SERVER 2016 Can Keep You Out of Trouble

You can see in above query we got an error of overflow.

Now, we are calculating the same difference from DATEDIFF_BIG in SQL SERVER 2016. See, below snap for same.


How DATEDIFF_BIG a new feature of SQL SERVER 2016 Can Keep You Out of Trouble

Isn’t it great ? Although, I am scarred with those applications who calculate milliseconds.

Anyways, it is good to know feature.

Do provide your feedback for the post it is very valuable for us.

RJ !!!


Viewing all articles
Browse latest Browse all 3160

Latest Images

Trending Articles