How to get the date difference in MySQL?
Â
I want to know the process to find the date difference in mysql in a emergency basis. Can anyone help?
Â
I want to know the process to find the date difference in mysql in a emergency basis. Can anyone help?
You can use the DATEDIFF function
It's pretty simple and you can use it to find the difference between two dates as long as the dates are valid
Â
the syntax is DATEDIFF( 1st date , 2nd date )
ex:Â SELECT DATEDIFF('2012-11-20','2008-11-20') AS DateDifference
Â
Note : If you used the date/time format the difference will be calculated from the date only
Â
In SQL, to dynamically get the current date (and time) you will need to type the following codes
select getdate()
Â
And to calculate the difference between two dates and get the result in days, months, years or minutes your syntax should be like this:
Days:select datediff (d, fromDATE, toDATE)
Months:select datediff (mm, fromDATE, toDATE)
Years:select datediff (yy, fromDATE, toDATE)
Minutes:select datediff (mi, fromDATE, toDATE)
Â