Sikander
Sikander

Reputation: 2835

MySQL : using datetime or timestamp for logged in history

I am doing an application where i have to store login and logout time for employees , now this is the logic

1- i'll query loggedin field to check if any value exists for today if not save current time (so i've to query and manipulate this value )

2- For logout every logout is last logout , so i've to keep track of the date to make sure last value is saved for today's date

3- there from admin panel i've to add functionality to search login / logout histroy using a jquery date picker ,

so as per this criteria can you guys please suggest me which one should i go for , i went through official docs but could not get this point

Upvotes: 0

Views: 476

Answers (1)

Lavi Avigdor
Lavi Avigdor

Reputation: 4182

They are both fit for your requirement. http://dev.mysql.com/doc/refman/5.7/en/datetime.html

The DATETIME type is used for values that contain both date and time parts. MySQL retrieves and displays DATETIME values in 'YYYY-MM-DD HH:MM:SS' format. The supported range is '1000-01-01 00:00:00' to '9999-12-31 23:59:59'.

The TIMESTAMP data type is used for values that contain both date and time parts. TIMESTAMP has a range of '1970-01-01 00:00:01' UTC to '2038-01-19 03:14:07' UTC.

Some difference:

MySQL converts TIMESTAMP values from the current time zone to UTC for storage, and back from UTC to the current time zone for retrieval. (This does not occur for other types such as DATETIME.)

Upvotes: 1

Related Questions