0
0
MySQLquery~20 mins

Time zone handling in MySQL - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Time Zone Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2:00remaining
Convert UTC timestamp to local time
Given a UTC timestamp '2024-06-01 12:00:00', which query correctly converts it to 'America/New_York' time zone?
MySQL
SELECT CONVERT_TZ('2024-06-01 12:00:00', 'UTC', 'America/New_York') AS local_time;
ASELECT CONVERT_TZ('2024-06-01 12:00:00', 'UTC', 'America/New_York') AS local_time;
BSELECT CONVERT_TZ('2024-06-01 12:00:00', 'UTC', 'Europe/London') AS local_time;
CSELECT CONVERT_TZ('2024-06-01 12:00:00', 'GMT', 'EST') AS local_time;
DSELECT CONVERT_TZ('2024-06-01 12:00:00', 'America/New_York', 'UTC') AS local_time;
Attempts:
2 left
💡 Hint
Remember that CONVERT_TZ(source_time, from_tz, to_tz) changes time from one zone to another.
🧠 Conceptual
intermediate
2:00remaining
Understanding MySQL time zone storage
Which statement about MySQL TIMESTAMP and DATETIME types regarding time zones is true?
ABoth TIMESTAMP and DATETIME store values as-is without any time zone conversion.
BDATETIME stores values in UTC and converts to session time zone on retrieval; TIMESTAMP stores values as-is without conversion.
CBoth TIMESTAMP and DATETIME store values in UTC and convert on retrieval.
DTIMESTAMP stores values in UTC and converts to session time zone on retrieval; DATETIME stores values as-is without time zone conversion.
Attempts:
2 left
💡 Hint
Think about how MySQL handles time zone conversion internally for these types.
📝 Syntax
advanced
2:00remaining
Identify the syntax error in time zone setting
Which option contains a syntax error when setting the time zone in MySQL?
MySQL
SET time_zone = 'America/Los_Angeles';
ASET time_zone = America/Los_Angeles;
BSET time_zone = 'America/Los_Angeles';
CSET time_zone = '+08:00';
DSET time_zone = '-05:00';
Attempts:
2 left
💡 Hint
Check if string literals are properly quoted.
optimization
advanced
2:00remaining
Optimizing queries with time zone conversion
You have a large table with UTC timestamps. Which approach is best to efficiently query rows within a local time range in 'Europe/Berlin' time zone?
AUse CONVERT_TZ on the timestamp column in the WHERE clause to compare with local times.
BConvert the local time range to UTC once, then query the UTC timestamp column using BETWEEN.
CStore timestamps as DATETIME in local time and query directly without conversion.
DUse UNIX_TIMESTAMP on the timestamp column and compare with UNIX timestamps of local times.
Attempts:
2 left
💡 Hint
Consider how functions in WHERE clauses affect index usage.
🔧 Debug
expert
3:00remaining
Debugging unexpected time zone conversion results
A query uses CONVERT_TZ but returns NULL for all rows. What is the most likely cause?
AThe session time zone is set to SYSTEM.
BThe input timestamp format is invalid.
CThe MySQL time zone tables are not loaded or incomplete.
DThe CONVERT_TZ function is deprecated and disabled.
Attempts:
2 left
💡 Hint
CONVERT_TZ returns NULL if it cannot find the time zone names.