Can a default value be specified for a DATE field in MySQL when creating a table with PHP?

When creating a table in MySQL using PHP, you can specify a default value for a DATE field by including it in the SQL query. You can use the DEFAULT keyword followed by the desired default date value in the format 'YYYY-MM-DD'. This will set the default value for the DATE field when a new record is inserted into the table.

<?php
// Connect to MySQL database
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "myDB";

$conn = new mysqli($servername, $username, $password, $dbname);

// Check connection
if ($conn->connect_error) {
  die("Connection failed: " . $conn->connect_error);
}

// Create table with default value for DATE field
$sql = "CREATE TABLE MyTable (
  id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
  event_date DATE DEFAULT '2022-01-01'
)";

if ($conn->query($sql) === TRUE) {
  echo "Table MyTable created successfully with default value for DATE field.";
} else {
  echo "Error creating table: " . $conn->error;
}

// Close connection
$conn->close();
?>