
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
Can we use current_date() for table with column timestamp default in MySQL?
Use the CURRENT_TIMESTAMP instead of current_date() in MySQL for timestamp default current_date. Let us first create a table. Following is the query −
mysql> create table defaultCurrent_DateDemo -> ( -> StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> StudentName varchar(20), -> StudentAdmissionDate timestamp default CURRENT_TIMESTAMP -> ); Query OK, 0 rows affected (0.55 sec)
Following is the query to insert some records in the table using insert command −
mysql> insert into defaultCurrent_DateDemo(StudentName) values('Larry'); Query OK, 1 row affected (0.52 sec) mysql> insert into defaultCurrent_DateDemo(StudentName,StudentAdmissionDate) values('Chris','2019-01-31'); Query OK, 1 row affected (0.18 sec)
Following is the query to display all records from the table using select statement −
mysql> select *from defaultCurrent_DateDemo;
This will produce the following output −
+-----------+-------------+----------------------+ | StudentId | StudentName | StudentAdmissionDate | +-----------+-------------+----------------------+ | 1 | Larry | 2019-04-02 19:38:19 | | 2 | Chris | 2019-01-31 00:00:00 | +-----------+-------------+----------------------+ 2 rows in set (0.00 sec)
- Related Articles
- How can we insert current date automatically in a column of MySQL table?
- How can we use MySQL EXPORT_SET() function with column of a table?
- Creating a Table in MySQL to set current date as default
- MySQL date column auto fill with current date?
- Can we use backticks with column value in MySQL?
- Display Timestamp before the current date in MySQL
- Can we use “year” as a column came in a MySQL Table?
- Can we use INTERVAL keyword while inserting date records in a MySQL table?
- Set current date and time to timestamp in MySQL
- Can we use the word user for a MySQL table?
- How can we insert current year automatically in a YEAR type column of MySQL table?
- How can we add columns with default values to an existing MySQL table?
- Can we use MySQL keyword as alias name for a column?
- How can we add day/s in the date stored in a column of MySQL table?
- How can we add a time interval to date stored in a column of MySQL table?

Advertisements