Friday , November 15 2024

DATEDIFF and DATEDIFF_BIG Functions in SQL Server(TSQL)

 

We can find the difference between the two dates using the following dateparts with the DATEDIFF function. The return data type is int.

If the int data type is insufficient for the difference between two dates, you should use the DATEDIFF_BIG function. You can use it in the same way as DATEDIFF function. Only return data type is bigint.

datepartAbbreviations
yearyy, yyyy
quarterqq, q
monthmm, m
dayofyeardy, y
daydd, d
weekwk, ww
weekdaydw, w
hourhh
minutemi, n
secondss, s
millisecondms
microsecondmcs
nanosecondns

Let’s make examples for a better understanding of DATEDIFF Function.

Find the month difference between two dates:

Loading

About dbtut

We are a team with over 10 years of database management and BI experience. Our Expertises: Oracle, SQL Server, PostgreSQL, MySQL, MongoDB, Elasticsearch, Kibana, Grafana.

Leave a Reply

Your email address will not be published. Required fields are marked *