How can the DATE_ADD function be used to manipulate dates in MySQL queries?
The DATE_ADD function in MySQL can be used to manipulate dates by adding a specified time interval to a given date. This function is useful for tasks like adding days, months, or years to a date. By using DATE_ADD in MySQL queries, you can easily perform date calculations and adjustments within your database operations.
// Example of using DATE_ADD function in MySQL query
$query = "SELECT DATE_ADD(date_column, INTERVAL 1 DAY) AS new_date FROM table_name";
$result = mysqli_query($connection, $query);
if ($result) {
while ($row = mysqli_fetch_assoc($result)) {
echo $row['new_date'] . "<br>";
}
} else {
echo "Error: " . mysqli_error($connection);
}
Keywords
Related Questions
- How can the PHP mail() function be modified to throw errors when incorrect data is passed?
- How can PHP developers efficiently extract and link specific form inputs, such as images, to corresponding objects in a database for effective data management?
- How can PHP developers avoid encoding issues when working with umlauts?