Question: I'm looking to calculate the number of months between 2 date time fields.

Is there a better way than getting the Unix timestamp and then dividing by 2 592 000 (seconds) and rounding up within MySQL?

Answer: 
[PERIOD\_DIFF](http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_period-diff) calculates months between two dates.

For example, to calculate the difference between now() and a time column in your\_table:

```
select period_diff(date_format(now(), '%Y%m'), date_format(time, '%Y%m')) as months from your_table;

```
The [DATEDIFF](http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html#function_datediff) function can give you the number of days between two dates. Which is more accurate, since... how do you define a month? (28, 29, 30, or 31 days?)