How can the DATE_ADD and INTERVAL functions in MySQL be used to manipulate dates in PHP?

To manipulate dates in MySQL using the DATE_ADD and INTERVAL functions in PHP, you can construct a SQL query that utilizes these functions to add or subtract a specific time interval from a date column in a database table. This can be useful for tasks such as calculating future or past dates, scheduling events, or performing date arithmetic operations.

// Connect to the database
$connection = mysqli_connect("localhost", "username", "password", "database");

// Define the date and interval
$date = "2022-01-01";
$interval = "1 DAY";

// Construct the SQL query
$query = "SELECT DATE_ADD(date_column, INTERVAL $interval) AS new_date FROM table WHERE date_column = '$date'";

// Execute the query
$result = mysqli_query($connection, $query);

// Fetch the result
while ($row = mysqli_fetch_assoc($result)) {
    echo $row['new_date'];
}

// Close the connection
mysqli_close($connection);