- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Set a MySQL field with the current date (UNIX_TIMESTAMP(now))
For this, use unix_timestamp(). Let us first create a table −
mysql> create table DemoTable1894 ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, DueTime int ); Query OK, 0 rows affected (0.00 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable1894 values(); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1894 values(); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1894 values(); Query OK, 1 row affected (0.00 sec)
Display all records from the table using select statement −
mysql> select * from DemoTable1894;
This will produce the following output −
+----+---------+ | Id | DueTime | +----+---------+ | 1 | NULL | | 2 | NULL | | 3 | NULL | +----+---------+ 3 rows in set (0.00 sec)
Here is the query to set a field with UNIX Timestamp −
mysql> update DemoTable1894 set DueTime=unix_timestamp(now()); Query OK, 3 rows affected (0.00 sec) Rows matched: 3 Changed: 3 Warnings: 0
Let us check the table records once again −
mysql> select * from DemoTable1894;
This will produce the following output −
+----+------------+ | Id | DueTime | +----+------------+ | 1 | 1576042722 | | 2 | 1576042722 | | 3 | 1576042722 | +----+------------+ 3 rows in set (0.00 sec)
- Related Articles
- How to insert current date/ time using now() in a field with MySQL?
- MySQL query to set current date in the datetime field for all the column values
- Calling NOW() function to fetch current date records in MySQL?
- UNIX_TIMESTAMP with date in MySQL query to fetch records after a specific date in different format?
- MySQL date column auto fill with current date?
- How to select a date less than the current date with MySQL?
- Set current date and time to timestamp in MySQL
- Creating a Table in MySQL to set current date as default
- Get the number of days between current date and date field?
- MySQL select * and find record with current date
- Grab where current date and the day before with MySQL?
- Select current time with MySQL now() and convert it to GMT 0?
- How to update date of datetime field with MySQL?
- Compare DATE string with string from MySQL DATETIME field?
- Update record on a specific date matching the current date in MySQL

Advertisements