
- 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
How to set default date time as system date time in MySQL?
You can use CURRENT_TIMESTAMP to set system date time.
Let us first create a table −
mysql> create table DemoTable ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, ClientFirstName varchar(20), ClientLastName varchar(20), ClientAge int ); Query OK, 0 rows affected (0.66 sec)
Following is the query to set default datetime as system date time in MySQL −
mysql> alter table DemoTable add column ClientProjectDeadline timestamp default current_timestamp; Query OK, 0 rows affected (0.46 sec) Records: 0 Duplicates: 0 Warnings: 0
Let us check the description of table once again −
mysql> desc DemoTable;
This will produce the following output −
+-----------------------+-------------+------+-----+-------------------+----------------+ | Field | Type | Null | Key | Default | Extra | +-----------------------+-------------+------+-----+-------------------+----------------+ | Id | int(11) | NO | PRI | NULL | auto_increment | | ClientFirstName | varchar(20) | YES | | NULL | | | ClientLastName | varchar(20) | YES | | NULL | | | ClientAge | int(11) | YES | | NULL | | | ClientProjectDeadline | timestamp | YES | | CURRENT_TIMESTAMP | | +-----------------------+-------------+------+-----+-------------------+----------------+ 5 rows in set (0.22 sec)
- Related Articles
- Set current date and time to timestamp in MySQL
- Creating a Table in MySQL to set current date as default
- How to insert current date/time in MySQL?
- Changing data type from date to date/time in MySQL?
- MySQL - Insert current date/time?
- How to order by date and time in MySQL?
- How to convert UTC date time into local date time using JavaScript?
- How to convert JS date time to MySQL datetime?
- How to part DATE and TIME from DATETIME in MySQL?
- How to group by date regardless of time in MySQL?
- Create DATETIME from DATE and TIME in MySQL?
- How can we offload the time/date handling in MySQL?
- Insert current time minus 1 hour to already inserted date-time records in MYSQL
- MySQL query to insert current date plus specific time?
- Sort by date & time in descending order in MySQL?

Advertisements