The default way to store a date in MySQL is with the type DATE
Format which is standard:
- YYYY-MM-DD
- Date Range: 1000-01-01 to 9999-12-31
To insert the current date into your table you can use MySQL's built-in function CURDATE() in your query. One is manual & second is using CURDATE()
PHP Code:
<?php
//This assumes you have already created the 'dateplayground' table
//Connect to DB
$query_manual = "INSERT INTO dateplayground (dp_name, dp_date)
VALUES ('DATE: Manual Date', '2020-2-14')";
$query_auto = "INSERT INTO dateplayground (dp_name, dp_date)
VALUE ('DATE: Auto CURDATE()', CURDATE() )";
mysql_query($query_manual) or die(mysql_error());
mysql_query($query_auto) or die(mysql_error());
?>
For detail information please follow this tutorial: http://www.tizag.com/mysqlTutorial/mysql-date.php
Bookmarks