How to get the date difference in MySQL?

Asked By 10 points N/A Posted on -
qa-featured

 

I want to know the process to find the date difference in mysql in a emergency basis. Can anyone help?

SHARE
Best Answer by Jayson03
Answered By 0 points N/A #151948

How to get the date difference in MySQL?

qa-featured

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

Best Answer
Best Answer
Answered By 0 points N/A #151949

How to get the date difference in MySQL?

qa-featured

 

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)

 

Related Questions