- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Which one should I use? The datetime or timestamp data type in MySQL?
Timestamp is a data type in MySQL and works for different time zone. It is also used for date and time purpose To understand the concept, we need to create a table.
Creating a table
mysql> CREATE table TimeStampDemo -> ( -> MyDataTime timestamp -> ); Query OK, 0 rows affected (0.57 sec)
After creating the table, we will insert a record with the help of INSERT command.
mysql> INSERT into TimeStampDemo values (now()); Query OK, 1 row affected (0.12 sec)
After inserting a record, we can display the records with the help of SELECT statement.
mysql> SELECT * from TimeStampDemo;
After executing the above query, we will get the following output
+---------------------+ | MyDataTime | +---------------------+ | 2018-10-11 17:30:38 | +---------------------+ 1 row in set (0.00 sec)
- What should one use CHAR data type or VARCHAR data type in MySQL?
- What is the difference between MySQL DATETIME and TIMESTAMP data type?
- Which datatype should I use for flag in MySQL?
- PHP string cast vs strval function, which one should I use?
- PHP timestamp to HTML5 input type=datetime element
- When should I use MySQL compressed protocol?
- How should I store data into my Mysql database, what type should I assign to a column storing salt values?
- How to convert timestamp to datetime in MySQL?
- When should I use a composite index in MySQL?
- Should I use COUNT(*) to get all the records in MySQL?
- What type of datatype should I use (MySQL) with a mix of string and number?
- Which one is better POW() or POWER() in MySQL?
- How to convert MySQL datetime to Unix timestamp?
- Why should I use Hubspot?
- Should I use MySQL enum or tinyint for fields having values 1 and 0?