Cú Pháp hàm DATEDIFF
DATEDIFF ( datepart , startdate , enddate )là các kiểu dữ liệu time, date, smalldatetime, datetime, datetime2, datetimeoffset . Trong hàm DATEDIFF chúng ta sẽ lấy enddate trừ cho startdate
Ví dụ cách dùng hàm DATEDIFF
SELECT DATEDIFF(year, '2005-12-31 23:59:59.9999999' , '2006-01-01 00:00:00.0000000'); SELECT DATEDIFF(quarter, '2005-12-31 23:59:59.9999999' , '2006-01-01 00:00:00.0000000'); SELECT DATEDIFF(month, '2005-12-31 23:59:59.9999999' , '2006-01-01 00:00:00.0000000'); SELECT DATEDIFF(dayofyear, '2005-12-31 23:59:59.9999999' , '2006-01-01 00:00:00.0000000'); SELECT DATEDIFF(day, '2005-12-31 23:59:59.9999999' , '2006-01-01 00:00:00.0000000'); SELECT DATEDIFF(week, '2005-12-31 23:59:59.9999999' , '2006-01-01 00:00:00.0000000'); SELECT DATEDIFF(hour, '2005-12-31 23:59:59.9999999' , '2006-01-01 00:00:00.0000000'); SELECT DATEDIFF(minute, '2005-12-31 23:59:59.9999999' , '2006-01-01 00:00:00.0000000'); SELECT DATEDIFF(second, '2005-12-31 23:59:59.9999999' , '2006-01-01 00:00:00.0000000'); SELECT DATEDIFF(millisecond, '2005-12-31 23:59:59.9999999' , '2006-01-01 00:00:00.0000000');
No comments:
Post a Comment