python ruby-programming-language Smalltalk Vue.js Knockoutjs TypeScript JavaScript, OOPs JavaScript Angular 7, Interview Questions Angular 8,7,6,5,4 and 2 Interview Questions and Answers Angular 8,7,6,5,4 and 2 Interview Questions and Answers Angular 4 Angular 2 AngularJs 1.x NodeJs Perl Programming R Programming RequireJs Rust Programming Backbonejs closure programming language go-programming-language kotlin-programming-language
sql datediff date format

SQL Server DateDiff - Date Format

The DATEDIFF function is use to get the differences in days, hours, minutes, seconds etc. and It is returns the time between two dates.

The DATEDIFF function can be used from above version of SQL Server 2005.

--Syntax
DATEDIFF(DATE_PART, START_DATE, END_DATE)

--Types of,
SELECT DATEDIFF(DAY, GETDATE(), GETDATE() + 1) AS DAY_DIFFERENCE 
SELECT DATEDIFF(WEEK, GETDATE(), GETDATE() + 1) AS WEEK_DIFFERENCE
SELECT DATEDIFF(HOUR, GETDATE(), GETDATE() + 1) AS HOUR_DIFFERENCE
SELECT DATEDIFF(MINUTE, GETDATE(), GETDATE() + 1) AS MINUTE_DIFFERENCE
SELECT DATEDIFF(SECOND, GETDATE(), GETDATE() + 1) AS SECOND_DIFFERENCE

-- Example as,
SELECT DATEDIFF(YEAR, '2015/04/28', '2016/04/28');
--RESULT is: 1

SELECT DATEDIFF(YYYY, '2015/04/28', '2016/04/28');
--RESULT is: 1

SELECT DATEDIFF(YY, '2015/04/28', '2016/04/28');
--RESULT is: 1

SELECT DATEDIFF(MONTH, '2015/01/01', '2016/04/28');
--RESULT is: 15

SELECT DATEDIFF(DAY, '2015/01/01', '2016/04/28');
--RESULT is: 483

SELECT DATEDIFF(HOUR, '2015/04/28 07:00', '2016/04/28 11:45');
--RESULT is: 8788

SELECT DATEDIFF(MINUTE, '2015/04/28 07:00', '2016/04/28 11:45');
--RESULT is: 527325

I hope you are enjoying with this post! Please share with you friends!! Thank you!!!

ANIL SINGH

Hi there! Welcome to my blog. My name is Anil Singh. I'm a author of this blog. For more detail about me, kindly refer to this link..
My Blogs - http://code-sample.com and http://code-sample.xyz
My Books - Interview Questions and Answers Books- Get Your Book in 15+ Digital Stores Worldwide..

You Might Also Like
www.code-sample.com/. Powered by Blogger.
ASK Questions