TIMESTAMPDIFF() in MySQL — How It Works

What the MySQL TIMESTAMPDIFF() function does, with an example.

Published October 20, 2026

TIMESTAMPDIFF() returns the difference between two datetimes in a specified unit (days, months, hours, etc.).

Key points

  • Part of standard SQL functions available in MySQL for working with dates and times

Example

SELECT TIMESTAMPDIFF(YEAR, birth_date, NOW()) FROM users;
More SQL articles