Introduction: We often in SQL to determine whether the year or month or the day is equal, we can use the DateDiff function, easy
DateDiff: Determine the number of differences in year or month or day or week, week, hour, minute, etc.
Use format:
DATEDIFF (Datepart,startdate,enddate)
Day (difference in days): can also be replaced with the following code
DATEDIFF (Day, ' 2008-12-29 ', ' 2008-12-30 ') as diffdate -result 1SELECT DATEDIFF (day, ' 2008-12-30 ', ' 2008-12-29 ') as Diffdate- The result is-1
Month (Month difference): You can also use the following code to replace
SELECT DATEDIFF (MM, ' 2008-12-30 ', ' 2010-12-29 ') as Diffdate -the result is 24
Year (difference in years): You can also use the following code to replace
SELECT DATEDIFF (year, ' 2008-12-30 ', ' 2010-12-29 ') as diffdate -result 2SELECT DATEDIFF (yy, ' 2008-12-30 ', ' 2010-12-29 ') ) as Diffdate --Results of 2
If you think reading this blog gives you something to gain, you might want to click " recommend " in the lower right corner.
If you want to find my new blog more easily, click on " Follow me "
If you want to give me more encouragement, you may wish to click on the right, " enjoy your stay"
Blog is his own summary of the results of learning, learning to summarize the knowledge-"analysis of the problem-" to solve the problem.
Where the views/descriptions in the text are incorrect, please correct them.
Thank you for your reading, if you are interested in the content of my blog, please continue to follow my following blog, I am yxtic.
Use of DateDiff in SQL