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 a CSV file that is hosted on the internet be opened using PHP?
- What are the best practices for inserting data into a table in PHP when certain conditions need to be met, such as checking for existing entries before insertion?
- What is the common issue with auto-incrementing IDs in PHP scripts and how can it lead to skipped numbers in the database?