
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Use Current Date for 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)
Advertisements