SQL Server Useful Code
Difference between datepart using DATEDIFF
SELECT DATEDIFF(year, '2011-12-31 22:59:59.9999999' , '2012-01-01 00:00:00.0000000');
SELECT DATEDIFF(quarter, '2011-12-31 22:59:59.9999999' , '2012-01-01 00:00:00.0000000');
SELECT DATEDIFF(month, '2011-12-31 22:59:59.9999999' , '2012-01-01 00:00:00.0000000');
SELECT DATEDIFF(dayofyear, '2011-12-31 22:59:59.9999999' , '2012-01-01 00:00:00.0000000');
SELECT DATEDIFF(day, '2011-12-31 22:59:59.9999999' , '2012-01-01 00:00:00.0000000');
SELECT DATEDIFF(week, '2011-12-31 22:59:59.9999999' , '2012-01-01 00:00:00.0000000');
SELECT DATEDIFF(hour, '2011-12-31 22:59:59.9999999' , '2012-01-01 00:00:00.0000000');
SELECT DATEDIFF(minute, '2011-12-31 22:59:59.9999999' , '2012-01-01 00:00:00.0000000');
SELECT DATEDIFF(second, '2011-12-31 22:59:59.9999999' , '2012-01-01 00:00:00.0000000');
SELECT DATEDIFF(millisecond, '2011-12-31 22:59:59.9999999' , '2012-01-01 00:00:00.0000000'
Comments
Post a Comment