Today to introduce six  useful MySQL's SQL statements, many people may have to implement these functions with PHP.
1 calculate the number of years
You want to calculate the birthday person how old.
SELECT DATE_FORMAT (FROM_DAYS (TO_DAYS (now ()) - TO_DAYS (@ dateofbirth)), '% Y') + 0;
2 the difference between the two time
Made the difference between two datetime values​​. Assuming datetime dt1 and dt2 are the type of the format 'yyyy-mm-dd hh: mm: ss', then the number of seconds difference between them is:
UNIX_TIMESP (dt2) - UNIX_TIMESP (dt1)
Divided by 60 is the difference between the number of minutes divided by 3600 is the difference between the number of hours, then divided by 24 is the difference between the number of days.
3 shows a column appeared in the value of N times
SELECT id
FROM tbl
GROUP BY id
HAVING COUNT (*) = N;
4 calculation of working days between two dates Read more