I need to create a playlist in database, to know when each video will be played by a player.
I will use something like this:
table playlist with: id, video_id, play_time
and for example if play_time is 2012-04-10 14:00:00 the video should be played at 14:00:00 on 2012-04-10 but related to timezone where user is located.
What it's better to use for this datetime or timestamp?
datetime
and store it in UTC (Europe/London) then you achieve the same effect as if you use a timestamp
, which defaults to UTC. Whatever happens, you need the information from your user about their timezone so you can calculate the offset you require. The answer is - both. You can use both types to store the date data. It's your app that provides your queries with required dates that need to include time zone offsets - N.B. 2012-04-04 09:15
From the MySQL manual:
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.) By default, the current time zone for each connection is the server's time. The time zone can be set on a per-connection basis. As long as the time zone setting remains constant, you get back the same value you store. If you store a TIMESTAMP value, and then change the time zone and retrieve the value, the retrieved value is different from the value you stored. This occurs because the same time zone was not used for conversion in both directions. The current time zone is available as the value of the time_zone system variable. For more information, see Section 9.6, “MySQL Server Time Zone Support”.
So the answer is: timestamp