What are the differences between using the DATE_FORMAT function and the date function in PHP for converting timestamps?

When converting timestamps in PHP, the DATE_FORMAT function is used to format a date string according to a specified format, while the date function is used to format a Unix timestamp into a human-readable date. The DATE_FORMAT function is typically used with MySQL queries to format dates directly in the database query, while the date function is used to format dates in PHP code.

// Using DATE_FORMAT function to format date in MySQL query
$query = "SELECT DATE_FORMAT(timestamp_column, '%Y-%m-%d') AS formatted_date FROM table_name";

// Using date function to format Unix timestamp in PHP code
$timestamp = time();
$formatted_date = date('Y-m-d', $timestamp);
echo $formatted_date;