A simple question that may come to one's mind while working with MySQL is "Whether to assign DATETIME or TIMESTAMP datatype for a column as both seem to store the same data?”. Even though they store the same data, they differ in some ways and let's check those things out with the help of a small example.
Introduction
A simple question that may come to one's mind while working with MySQL is "Whether to assign DATETIME or TIMESTAMP datatype for a column as both seem to store the same data?”. Even though they store the same data, they differ in some ways; let's check those things out with the help of a small example.
Similarities between DATETIME & TIMESTAMP
Difference between DATETIME & TIMESTAMP
Example (DATETIME)
My system time zone is IST, so by default, MySQL uses IST time zone.
OUTPUT
entry_time
___________________
2017-11-17 07:38:07
Now, let's change the system time zone from IST to EST, i.e., UTC - 05:00 during cold months of Daylight Saving Time.
____________________
2017-11-17 07:45:01
Example (TIMESTAMP)
The result is the same even though we changed the time zone.
2017-11-17 07:49:33
entry_time____________________
2017-11-16 12:19:3
Conclusion
The above result is subject to change to the set time zone, i.e., EST which is -5hrs from UTC time.
Even though both datatypes look similar, these are way different than what we might have thought of. Hope this small tip will help someone in some way for differentiating these 2 confusing datatypes. Please share your feedback if you find this tip helpful for you.
Reference
Introduction to Mongo DB