MySql DATEDIFF() Working Example and Uses

In This tutorial i will describe how to use DateDiff() function of MySql.Date difference is very important function of MySql.Normally we will use server side script to operation of data,but based on performance its very costly,To avoid Server side script MySql provide Date difference function to get refined result from database.


Where date1 and date2 are valid date or date/time expressions.


SELECT DATEDIFF('2012-11-09','2012-11-08')

Note: Only the date parts of the values are used in the calculation so that Above statement will return the days between two datetime expressions.



Below script about how to get all result which is below 2 days from now.
[code type=”sql”]
$sql = “SELECT appToken.ExpiryDate,appToken.ApplicationId,app.Name,app.ApplicationSiteId FROM applicationtoken as appToken inner join application as app on app.ApplicationId =appToken.ApplicationId AND DATEDIFF(appToken.ExpiryDate,now()) <= 2"; $results = $this->dataObj->GetData($sql);
$isEmailSend = 1;