- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- 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)
Advertisements