Course outline

MySQL / Relational foundations and precise SQL / Lesson 7

Date boundaries and session time zones

Model time deliberately and build an unambiguous half-open reporting interval.

About 22 min read20 worked examples20 practice exercisesContent reviewed
On this page

Lesson goals

  • Distinguish a calendar value from an instant and session context.
  • Write a half-open time interval with deterministic ordering.
  • Test boundary values and time-zone assumptions.
  • Predict membership at exact and fractional half-open boundaries.
  • Relate TIMESTAMP session conversion to business-zone reporting and daylight-saving changes.

Define what the value means

An order date, a local appointment time, and a globally ordered event instant are different facts. Before selecting a temporal type, document the business time zone, precision, allowed range, and conversion policy. MySQL DATETIME and TIMESTAMP have different ranges and time-zone behavior; the application and session settings must be considered with the chosen type. A displayed clock value alone does not identify the full contract.

Create a boundary fixture

The following illustrative SQL belongs only in a new disposable MySQL 8.4 lab. It defines local calendar values with DATETIME and does not connect to a configured server. The three rows lie at the beginning and end of one calendar day and at the beginning of the next. In this exercise, all values are interpreted in the same explicitly agreed business calendar.

sql Three events around a day boundary
CREATE TABLE lab_event (
  id INT PRIMARY KEY,
  event_at DATETIME NOT NULL,
  label VARCHAR(40) NOT NULL
) ENGINE=InnoDB;
INSERT INTO lab_event VALUES
  (1, '2026-01-01 00:00:00', 'opening'),
  (2, '2026-01-01 23:59:59', 'closing'),
  (3, '2026-01-02 00:00:00', 'next day');

The fixture provides two events during January 1 and one exactly at the start of January 2. DATETIME here represents the agreed calendar values; no time-zone conversion or live output is asserted.

Use an inclusive start and exclusive end

A half-open interval includes its lower boundary and excludes the next period’s beginning. It avoids inventing a final fractional second and makes adjacent periods fit without overlap. Use typed bound parameters in application code and calculate the period boundaries under the agreed calendar and time-zone policy before sending them. The fixed literals below make the training result easy to inspect.

sql Select one calendar day
SELECT id, event_at, label FROM lab_event
WHERE event_at >= '2026-01-01 00:00:00'
  AND event_at <  '2026-01-02 00:00:00'
ORDER BY event_at, id;

Rows 1 and 2 match the fixture interval. Row 3 is exactly the exclusive upper boundary and is excluded. ORDER BY gives a deterministic order using the identifier as a tie-breaker.

Check session and conversion behavior

MySQL converts TIMESTAMP values between the session time zone and UTC for storage and retrieval, while DATETIME values are not converted in the same way. Named zones require the server’s time-zone tables to be maintained. Test the deployed connector, session configuration, daylight-saving transitions, and permitted range; do not assume that a connection pool retains the desired setting without initialization and verification.

Verify the business boundary

Test a value immediately before the interval, both exact boundaries, and a value with supported fractional precision just inside the end. Include a daylight-saving transition if the business uses local dates. Compare results to a hand-written expectation and inspect the connection’s effective time zone. A report may be syntactically correct yet assign events to the wrong day when the boundary was calculated in another zone.

Specify the temporal contract

A calendar date, a local wall-clock appointment, and an instant are different kinds of facts. A DATE such as 2026-01-01 identifies a day but not a time or time zone. A DATETIME can record a calendar date and clock value; it does not by itself say which zone the writer intended. A TIMESTAMP is converted between the session time zone and UTC when MySQL stores and retrieves it. Its interpretation therefore depends on the session and connector contract as well as the stored instant.

Before defining a report, write down the business zone, the type and precision of each source column, the input boundary convention and the expected output zone. A shop that closes its books by local day must calculate boundaries for that local calendar, not assume every day begins at UTC midnight. Keep any named business zone needed for future interpretation separately from the timestamp. Examples here use the lesson’s synthetic lab_event DATETIME fixture unless another scenario explicitly states its assumptions.

Partition time with half-open ranges

For a day beginning at start and ending at next_start, use event_at >= start AND event_at < next_start. The lower instant belongs to the day; the upper instant belongs to the next day. In the baseline fixture, event 1 at January 1 midnight and event 2 at 23:59:59 match January 1, while event 3 at January 2 midnight does not. Adjacent ranges share a boundary without sharing an event. This is easier to reason about than inventing a final second or a final fractional value.

A DATETIME(6) value just before midnight can contain microseconds, such as 23:59:59.999999. An inclusive upper bound of 23:59:59 excludes that later value. A next-midnight exclusive bound includes it at supported precision. The actual column precision and conversion of bound parameters still matter: test values exactly at both ends, immediately inside and outside, and ties in ordering. Do not infer a stable row sequence unless ORDER BY includes a unique tie-breaker.

Control the session and conversion

The MySQL session time_zone affects TIMESTAMP conversion on insertion and retrieval. If a TIMESTAMP is inserted in a +02:00 session as 12:00, the corresponding UTC instant is 10:00; reading that instant in a +00:00 session displays 10:00. These fixed-offset examples avoid daylight-saving assumptions. DATETIME calendar fields are not converted in the same way, so identical displayed values in the two types do not automatically represent the same instant.

Set and verify session time_zone on each connection according to the application contract, including connections borrowed from a pool. Named zones such as Europe/Paris require correctly populated and maintained MySQL time-zone tables; conversion results also depend on the rules for the date in question. Check NULL or errors from failed conversions rather than accepting a missing boundary. Session configuration is not a replacement for documenting the business zone or testing the deployed driver and its parameter behavior.

Treat local days as calendar intervals

A local day around a daylight-saving transition may span 23 or 25 elapsed hours. Calculate the local beginning of the requested date and the local beginning of the next date under the appropriate zone rules, then convert each boundary to the instant representation used by the query. Adding a fixed 24 hours to the first instant can put the end in the wrong local day. The examples involving a transition must state their offset assumptions; real named-zone behavior requires current zone data and verification in the target environment.

A local clock value can be ambiguous when clocks move backward or nonexistent when they move forward. A bare DATETIME cannot distinguish two occurrences of an ambiguous wall time. Define how the application rejects, disambiguates or stores such input, including the zone and offset where needed. Preserve the original business meaning rather than relying on whichever conversion a library happens to choose. For recurring appointments, a local time plus zone may express the intention more faithfully than a single precomputed UTC offset.

Verify boundaries and result order

Build a small table of expected events before writing the report: one immediately before the start, one at the start, one just before the end and one exactly at the end. For the half-open range, only the middle two qualify. Test a fractional second at the supported precision and a pair of events with identical event_at values. ORDER BY event_at, id yields a unique sequence if id is unique; ordering by time alone does not resolve the tie.

When a report uses TIMESTAMP, check the effective session zone and convert both boundaries under the same documented policy. Test the actual connector, precision and allowed type range in an isolated MySQL 8.4 lab, including daylight-saving transitions if the business zone uses them. Record whether outputs are local calendar values or UTC instants. SQL below is non-runnable teaching material and outputs are reasoned from explicit synthetic assumptions, not measured against a server.

20 worked examples

1. Inclusive start

Problem: Does event 1 at the exact January 1 start belong to that day?

  1. Event 1 equals the lower boundary 2026-01-01 00:00:00.
  2. The greater-than-or-equal comparison includes that boundary, and it is before the end.
sql Inclusive start
SELECT id FROM lab_event WHERE event_at >= '2026-01-01 00:00:00' AND event_at < '2026-01-02 00:00:00' AND id = 1;
Expected output
1

Illustrative MySQL 8.4 SQL using synthetic disposable fixtures and stated offsets; results are reasoned and not locally executed.

Expected result: Event 1 is included.

Why this result follows: A half-open interval explicitly includes its start and excludes its end. This follows the stated boundaries and synthetic assumptions.

2. Exclusive end

Problem: Does event 3 at the exact January 2 start belong to January 1?

  1. Event 3 equals the upper boundary 2026-01-02 00:00:00.
  2. The strict less-than comparison excludes equality with that boundary.
sql Exclusive end
SELECT id FROM lab_event WHERE event_at >= '2026-01-01 00:00:00' AND event_at < '2026-01-02 00:00:00' AND id = 3;
Expected output
No rows.

Illustrative MySQL 8.4 SQL using synthetic disposable fixtures and stated offsets; results are reasoned and not locally executed.

Expected result: Event 3 is excluded.

Why this result follows: The exclusive end assigns the midnight boundary to the following period. This follows the stated boundaries and synthetic assumptions.

3. Adjacent days

Problem: Which fixture event belongs to the January 2 interval rather than January 1?

  1. Event 3 equals the inclusive start of January 2.
  2. Events 1 and 2 occur on January 1 and precede that start.
sql Adjacent days
SELECT id FROM lab_event WHERE event_at >= '2026-01-02 00:00:00' AND event_at < '2026-01-03 00:00:00' ORDER BY id;
Expected output
3

Illustrative MySQL 8.4 SQL using synthetic disposable fixtures and stated offsets; results are reasoned and not locally executed.

Expected result: Event 3.

Why this result follows: Adjacent half-open ranges meet at midnight without counting that event twice. This follows the stated boundaries and synthetic assumptions.

4. Before start

Problem: Does a synthetic event immediately before January 1 match its day range?

  1. The synthetic clock value occurs one second before the lower boundary.
  2. The greater-than-or-equal comparison is false for that value.
sql Before start
SELECT '2025-12-31 23:59:59' >= '2026-01-01 00:00:00' AS meets_start;
Expected output
0

Illustrative MySQL 8.4 SQL using synthetic disposable fixtures and stated offsets; results are reasoned and not locally executed.

Expected result: 0; it is excluded.

Why this result follows: A value before the inclusive start is outside the interval regardless of the end.

5. Fractional end

Problem: Does a microsecond value just before midnight match a half-open day?

  1. The synthetic value is one microsecond earlier than the next midnight.
  2. The strict upper-bound comparison is therefore true at DATETIME(6) precision.
sql Fractional end
SELECT CAST('2026-01-01 23:59:59.999999' AS DATETIME(6)) < CAST('2026-01-02 00:00:00' AS DATETIME(6)) AS inside_end;
Expected output
1

Illustrative MySQL 8.4 SQL using synthetic disposable fixtures and stated offsets; results are reasoned and not locally executed.

Expected result: 1; it is inside.

Why this result follows: Using the next period start includes supported fractional instants before that boundary.

6. Last-second trap

Problem: Does an inclusive 23:59:59 upper bound include a later fractional value?

  1. The synthetic event occurs half a second after 23:59:59.000000.
  2. It is later than the guessed inclusive upper bound even though it is on January 1.
sql Last-second trap
SELECT CAST('2026-01-01 23:59:59.500000' AS DATETIME(6)) <= CAST('2026-01-01 23:59:59' AS DATETIME(6)) AS included;
Expected output
0

Illustrative MySQL 8.4 SQL using synthetic disposable fixtures and stated offsets; results are reasoned and not locally executed.

Expected result: 0; the event is missed.

Why this result follows: A last-second bound omits fractional values later in that same second. This follows the stated boundaries and synthetic assumptions.

7. Deterministic order

Problem: What order is guaranteed for the three baseline events by time and id?

  1. The fixture timestamps progress from January 1 midnight to January 2 midnight.
  2. The unique id provides a tie-breaker if equal timestamps are later introduced.
sql Deterministic order
SELECT id FROM lab_event ORDER BY event_at, id;
Expected output
1
2
3

Illustrative MySQL 8.4 SQL using synthetic disposable fixtures and stated offsets; results are reasoned and not locally executed.

Expected result: 1, 2, 3.

Why this result follows: Explicit ordering defines the display sequence independently of physical table order. This follows the stated boundaries and synthetic assumptions.

8. Time tie

Problem: How are two synthetic events with identical times ordered by id?

  1. Both rows have the same event_at, so the first sort key ties.
  2. Ascending id breaks the tie, placing 4 before 9.
sql Time tie
SELECT x.id FROM (SELECT 9 AS id, CAST('2026-01-01 10:00:00' AS DATETIME) AS event_at UNION ALL SELECT 4, CAST('2026-01-01 10:00:00' AS DATETIME)) x ORDER BY x.event_at, x.id;
Expected output
4
9

Illustrative MySQL 8.4 SQL using synthetic disposable fixtures and stated offsets; results are reasoned and not locally executed.

Expected result: 4, then 9.

Why this result follows: A unique secondary sort key makes equal-time results deterministic. This follows the stated boundaries and synthetic assumptions.

9. Monthly boundary

Problem: Which shop orders fall within January using the next-month boundary?

  1. All three fixture orders occur on January 10, 11, or 12.
  2. Each timestamp is at or after January 1 and before February 1.
sql Monthly boundary
SELECT id FROM orders WHERE placed_at >= '2026-01-01' AND placed_at < '2026-02-01' ORDER BY id;
Expected output
101
102
103

Illustrative MySQL 8.4 SQL using synthetic disposable fixtures and stated offsets; results are reasoned and not locally executed.

Expected result: Orders 101, 102, and 103.

Why this result follows: The next-month exclusive bound includes the entire preceding calendar month. This follows the stated boundaries and synthetic assumptions.

10. Midnight only

Problem: What does a same-midnight inclusive range select from the event fixture?

  1. The two comparisons constrain event_at to exactly the same midnight value.
  2. Only event 1 has that exact value; event 2 is later on the same day.
sql Midnight only
SELECT id FROM lab_event WHERE event_at >= '2026-01-01 00:00:00' AND event_at <= '2026-01-01 00:00:00' ORDER BY id;
Expected output
1

Illustrative MySQL 8.4 SQL using synthetic disposable fixtures and stated offsets; results are reasoned and not locally executed.

Expected result: Event 1 only.

Why this result follows: A date start used for both bounds selects one instant rather than the entire day.

11. Fixed-offset conversion

Problem: What UTC clock time corresponds to 12:00 at a fixed +02:00 offset?

  1. The source clock is two hours ahead of UTC in the stated fixed-offset scenario.
  2. Subtracting two hours converts 12:00 to 10:00 on the same date.
sql Fixed-offset conversion
SELECT CONVERT_TZ('2026-01-01 12:00:00', '+02:00', '+00:00') AS utc_time;
Expected output
2026-01-01 10:00:00

Illustrative MySQL 8.4 SQL using synthetic disposable fixtures and stated offsets; results are reasoned and not locally executed.

Expected result: 2026-01-01 10:00:00 UTC.

Why this result follows: Fixed-offset conversion preserves the instant while changing its clock representation. This follows the stated boundaries and synthetic assumptions.

12. Offset crosses date

Problem: What UTC date and time correspond to 00:30 at fixed +02:00?

  1. The source offset is two hours ahead of UTC.
  2. Subtracting two hours from 00:30 crosses back into the previous calendar date.
sql Offset crosses date
SELECT CONVERT_TZ('2026-01-01 00:30:00', '+02:00', '+00:00') AS utc_time;
Expected output
2025-12-31 22:30:00

Illustrative MySQL 8.4 SQL using synthetic disposable fixtures and stated offsets; results are reasoned and not locally executed.

Expected result: 2025-12-31 22:30:00 UTC.

Why this result follows: Changing a clock representation can change the calendar date without changing the instant.

13. Opposite offset

Problem: What UTC time corresponds to 23:00 at a fixed -05:00 offset?

  1. The source clock is five hours behind UTC.
  2. Adding five hours to 23:00 crosses into January 2.
sql Opposite offset
SELECT CONVERT_TZ('2026-01-01 23:00:00', '-05:00', '+00:00') AS utc_time;
Expected output
2026-01-02 04:00:00

Illustrative MySQL 8.4 SQL using synthetic disposable fixtures and stated offsets; results are reasoned and not locally executed.

Expected result: 2026-01-02 04:00:00 UTC.

Why this result follows: Fixed-offset arithmetic can move an instant into the next UTC calendar day.

14. Local day in UTC

Problem: What UTC boundaries describe January 1 at a fixed +02:00 offset?

  1. Convert each local midnight separately by subtracting the fixed two-hour offset.
  2. The result spans from December 31 at 22:00 to January 1 at 22:00 UTC.
sql Local day in UTC
SELECT CONVERT_TZ('2026-01-01 00:00:00', '+02:00', '+00:00') AS start_utc, CONVERT_TZ('2026-01-02 00:00:00', '+02:00', '+00:00') AS end_utc;
Expected output
2025-12-31 22:00:00 | 2026-01-01 22:00:00

Illustrative MySQL 8.4 SQL using synthetic disposable fixtures and stated offsets; results are reasoned and not locally executed.

Expected result: [2025-12-31 22:00:00, 2026-01-01 22:00:00) UTC.

Why this result follows: Converting both endpoints preserves the intended local half-open day in UTC. This follows the stated boundaries and synthetic assumptions.

15. DATETIME meaning

Problem: What date is stored in the baseline event 2 calendar value?

  1. Event 2 is recorded as 2026-01-01 23:59:59 in DATETIME.
  2. DATE extracts the calendar date portion of that stored value.
sql DATETIME meaning
SELECT DATE(event_at) AS event_day FROM lab_event WHERE id = 2;
Expected output
2026-01-01

Illustrative MySQL 8.4 SQL using synthetic disposable fixtures and stated offsets; results are reasoned and not locally executed.

Expected result: 2026-01-01.

Why this result follows: The extracted date is a calendar fact and does not by itself identify a time zone.

16. Session inspection

Problem: Which expression reveals the current session time-zone setting?

  1. The system variable describes the effective session setting, not the business zone automatically.
  2. Its value must be observed in the actual connection rather than guessed from this fixture.
sql Session inspection
SELECT @@session.time_zone AS session_zone;
Expected output
Depends on the isolated session configuration.

Illustrative MySQL 8.4 SQL using synthetic disposable fixtures and stated offsets; results are reasoned and not locally executed.

Expected result: The configured session value.

Why this result follows: Inspecting the session makes an otherwise hidden conversion assumption explicit. This follows the stated boundaries and synthetic assumptions.

17. Timestamp fixed offset

Problem: What does a TIMESTAMP display after insertion at +02:00 and reading at +00:00?

  1. Insertion interprets 12:00 using the stated +02:00 session offset.
  2. Retrieval in +00:00 displays the same instant as 10:00 UTC.
sql Timestamp fixed offset
SET time_zone = '+02:00';
CREATE TABLE lab_ts (id INT PRIMARY KEY, event_at TIMESTAMP NOT NULL) ENGINE=InnoDB;
INSERT INTO lab_ts VALUES (1, '2026-01-01 12:00:00');
SET time_zone = '+00:00';
SELECT event_at FROM lab_ts WHERE id = 1;
Expected output
2026-01-01 10:00:00

Illustrative MySQL 8.4 SQL using synthetic disposable fixtures and stated offsets; results are reasoned and not locally executed.

Expected result: 2026-01-01 10:00:00.

Why this result follows: TIMESTAMP conversion uses the session offset on input and output for this scenario.

18. DATETIME fixed offset

Problem: Does changing session offset convert a DATETIME value like TIMESTAMP?

  1. The inserted DATETIME records the supplied calendar date and clock value.
  2. Changing the session offset does not perform TIMESTAMP-style conversion on it.
sql DATETIME fixed offset
SET time_zone = '+02:00';
CREATE TABLE lab_dt (id INT PRIMARY KEY, event_at DATETIME NOT NULL) ENGINE=InnoDB;
INSERT INTO lab_dt VALUES (1, '2026-01-01 12:00:00');
SET time_zone = '+00:00';
SELECT event_at FROM lab_dt WHERE id = 1;
Expected output
2026-01-01 12:00:00

Illustrative MySQL 8.4 SQL using synthetic disposable fixtures and stated offsets; results are reasoned and not locally executed.

Expected result: 2026-01-01 12:00:00.

Why this result follows: DATETIME and TIMESTAMP have different session time-zone conversion behavior. This follows the stated boundaries and synthetic assumptions.

19. Short local day

Problem: How long is a hypothetical local day whose offset changes from +01:00 to +02:00?

  1. The stated offsets convert the two local midnights to 23:00 and 22:00 UTC.
  2. The UTC interval between those endpoints is 23 elapsed hours.
sql Short local day
-- Local boundaries: 2026-03-29 00:00 at +01:00; 2026-03-30 00:00 at +02:00.
SELECT TIMESTAMPDIFF(HOUR, '2026-03-28 23:00:00', '2026-03-29 22:00:00') AS elapsed_hours;
Expected output
23

Illustrative MySQL 8.4 SQL using synthetic disposable fixtures and stated offsets; results are reasoned and not locally executed.

Expected result: 23 hours.

Why this result follows: Each boundary uses its own offset, so a local day need not last 24 hours.

20. Long local day

Problem: How long is a hypothetical local day whose offset changes from +02:00 to +01:00?

  1. The stated offsets convert the local midnights to 22:00 and 23:00 UTC.
  2. The elapsed interval between those UTC endpoints is 25 hours.
sql Long local day
-- Local boundaries: 2026-10-25 00:00 at +02:00; 2026-10-26 00:00 at +01:00.
SELECT TIMESTAMPDIFF(HOUR, '2026-10-24 22:00:00', '2026-10-25 23:00:00') AS elapsed_hours;
Expected output
25

Illustrative MySQL 8.4 SQL using synthetic disposable fixtures and stated offsets; results are reasoned and not locally executed.

Expected result: 25 hours.

Why this result follows: A backward offset change lengthens the stated local calendar interval to 25 hours.

Common errors and fixes

An event at midnight appears in two adjacent reports.

Why it happens
Both period endpoints were made inclusive.
How to fix it
Use an inclusive start and exclusive next-period boundary.
Prevent it next time
Test exact boundaries for adjacent periods.

A report assigns an event to the wrong day.

Why it happens
The application and session used different time-zone assumptions.
How to fix it
Determine the intended business zone and initialize and verify the session contract.
Prevent it next time
Test zone conversion and daylight-saving boundaries through the deployed connector.

A late fractional-second event is missing.

Why it happens
The upper bound was written as a guessed last second of the day.
How to fix it
Use the next period’s start as an exclusive bound.
Prevent it next time
Include fractional boundary cases in report tests.

20 practice exercises

1. Which fixture rows belong to January 1 under the shown interval?

Show hint

Test each row against both the inclusive start and exclusive end.

Show worked solution

Rows 1 and 2. Row 1 equals the inclusive start, row 2 is before the exclusive end, and row 3 equals the next day’s start and is excluded.

Event 1 equals the January 1 start and event 2 is later that day, so both match. Event 3 equals January 2 midnight and is excluded from the January 1 range.

Check your solution

  • Include ids 1 and 2.
  • Exclude id 3 at the upper boundary.

2. What should be checked before applying the same literals to TIMESTAMP values?

Show hint

Separate the business calendar from session conversion and connector behavior.

Show worked solution

Check the business zone, session time zone, connector behavior, TIMESTAMP range, and how boundaries were converted. The displayed local values alone do not establish equivalent instants.

TIMESTAMP conversion uses the session time zone, so check the business zone, effective session setting, connector parameter behavior, permitted range and conversion of both boundaries. The same clock literals need not refer to the same instants under different settings.

Check your solution

  • Verify session and connector assumptions.
  • Check range and both converted boundaries.

3. For the baseline fixture, identify the January 2 event using a half-open daily interval.

Show hint

Trace the stated boundaries, precision, and applicable offset separately.

Show worked solution

Use event_at >= '2026-01-02 00:00:00' AND event_at < '2026-01-03 00:00:00'. Event 3 is exactly at the inclusive start and matches. Events 1 and 2 are on January 1 and therefore precede the lower bound.

Check your solution

  • Event 3
  • Next midnight is excluded

4. A synthetic event is at 2026-01-01 23:59:59.999999. Is it inside the January 1 half-open day?

Show hint

Trace the stated boundaries, precision, and applicable offset separately.

Show worked solution

Yes, at DATETIME(6) precision the value precedes 2026-01-02 00:00:00 by one microsecond. It satisfies the exclusive upper bound and follows the inclusive start. An upper bound of 23:59:59 would incorrectly exclude this fractional event.

Check your solution

  • Include the fractional event
  • Use next midnight as exclusive end

5. A report uses BETWEEN with both adjacent day endpoints inclusive. Explain the midnight defect.

Show hint

Trace the stated boundaries, precision, and applicable offset separately.

Show worked solution

BETWEEN includes both endpoints, so an event exactly at the shared midnight can appear in both daily reports. Use an inclusive start and exclusive next-day start for each report. The midnight event then belongs only to the later day.

Check your solution

  • Shared midnight would be counted twice
  • Use >= start and < next start

6. Convert 2026-01-01 15:00 at fixed +03:00 to UTC and state the resulting date.

Show hint

Trace the stated boundaries, precision, and applicable offset separately.

Show worked solution

Subtract the fixed three-hour offset from the local clock value. The result is 2026-01-01 12:00 UTC, on the same calendar date. This is fixed-offset arithmetic; a named region may have a different offset on another date.

Check your solution

  • UTC time 12:00
  • UTC date January 1

7. Convert 2026-01-01 01:00 at fixed +03:00 to UTC and identify any date crossing.

Show hint

Trace the stated boundaries, precision, and applicable offset separately.

Show worked solution

Subtract three hours from 01:00. The UTC representation is 2025-12-31 22:00, crossing into the previous date. The instant itself is unchanged; only the calendar representation differs between the stated offset and UTC.

Check your solution

  • UTC time 22:00
  • UTC date December 31, 2025

8. Convert 2026-01-01 22:00 at fixed -04:00 to UTC and identify the resulting date.

Show hint

Trace the stated boundaries, precision, and applicable offset separately.

Show worked solution

Add four hours because the source clock is four hours behind UTC. The result is 2026-01-02 02:00 UTC, on the following day. Always apply the offset to both report boundaries rather than assuming local midnight is UTC midnight.

Check your solution

  • UTC time 02:00
  • UTC date January 2

9. For fixed +03:00, calculate the UTC interval for the local day beginning January 2.

Show hint

Trace the stated boundaries, precision, and applicable offset separately.

Show worked solution

Local January 2 midnight converts to January 1 at 21:00 UTC; local January 3 midnight converts to January 2 at 21:00 UTC. Use the half-open interval between those endpoints. Both boundaries use the stated fixed offset in this scenario.

Check your solution

  • Start January 1 21:00 UTC
  • End January 2 21:00 UTC exclusive

10. Two events share event_at but have ids 5 and 8. Give a deterministic ascending order.

Show hint

Trace the stated boundaries, precision, and applicable offset separately.

Show worked solution

Use ORDER BY event_at, id. The timestamps tie, so the unique id decides the sequence: 5 then 8. Ordering by event_at alone does not promise which tied row is displayed first, even if one order appears repeatedly during testing.

Check your solution

  • Order ids 5 then 8
  • Use id as tie-breaker

11. Explain why a DATE value alone cannot identify a globally unique event instant.

Show hint

Trace the stated boundaries, precision, and applicable offset separately.

Show worked solution

A DATE records a calendar day but contains no clock time or time-zone offset. Many instants can fall on that date in one zone, and the same date has different UTC boundaries in different zones. Specify the additional time and zone semantics required by the event.

Check your solution

  • No time of day
  • No zone or offset

12. A DATETIME stores 2026-01-01 12:00 without a documented zone. What information is missing?

Show hint

Trace the stated boundaries, precision, and applicable offset separately.

Show worked solution

The value supplies a calendar date and clock time but not whether it means UTC, a local business time, or another convention. Document the zone, precision and conversion policy, and test each writer and reader. A displayed clock value alone cannot establish a unique instant.

Check your solution

  • Zone or convention missing
  • Document conversion policy

13. A TIMESTAMP is read through a pooled connection. State the session check required for predictable display.

Show hint

Trace the stated boundaries, precision, and applicable offset separately.

Show worked solution

Initialize and inspect the connection’s session time_zone according to the application contract before relying on TIMESTAMP conversion. A pooled connection can carry a prior session setting. Verify connector behavior and the intended business zone separately; the session setting alone does not define the report.

Check your solution

  • Check @@session.time_zone
  • Initialize pooled connections

14. A named zone conversion returns NULL in an isolated test. What configuration should be investigated?

Show hint

Trace the stated boundaries, precision, and applicable offset separately.

Show worked solution

Check whether the named zone exists in correctly populated MySQL time-zone tables and whether the input is valid for the intended conversion. Also inspect server configuration and date-specific zone rules. Do not silently use NULL as a report boundary; surface and resolve the conversion failure.

Check your solution

  • Check time-zone tables
  • Do not use NULL boundary silently

15. A local day starts at offset +01:00 and ends at +02:00. Calculate its elapsed length.

Show hint

Trace the stated boundaries, precision, and applicable offset separately.

Show worked solution

The start midnight converts to 23:00 UTC on the previous day and the next midnight converts to 22:00 UTC on the named day. The difference is 23 hours. Convert each endpoint with its applicable offset rather than adding 24 hours to the first instant.

Check your solution

  • Elapsed length 23 hours
  • Convert each endpoint independently

16. A local day starts at offset +02:00 and ends at +01:00. Calculate its elapsed length.

Show hint

Trace the stated boundaries, precision, and applicable offset separately.

Show worked solution

The start midnight converts to 22:00 UTC on the previous day, while the next midnight converts to 23:00 UTC on the named day. The elapsed interval is 25 hours. This scenario states its offsets explicitly; verify real zone rules for the target dates.

Check your solution

  • Elapsed length 25 hours
  • Verify actual zone rules

17. A backward clock change repeats a local 01:30. Explain why a bare DATETIME is ambiguous.

Show hint

Trace the stated boundaries, precision, and applicable offset separately.

Show worked solution

The same wall-clock value can refer to two distinct instants when the offset changes backward. A DATETIME alone does not record which occurrence was intended. Define a disambiguation policy and preserve the relevant zone or offset alongside the value when the business needs an instant.

Check your solution

  • Two possible instants
  • Record or resolve zone and offset

18. An event exactly matches the exclusive upper boundary. State which adjacent day should contain it.

Show hint

Trace the stated boundaries, precision, and applicable offset separately.

Show worked solution

It does not belong to the earlier half-open interval because that interval uses a strict less-than upper bound. It belongs to the following interval when the same instant is its inclusive lower bound. This assigns the event once without a gap or overlap.

Check your solution

  • Exclude from earlier day
  • Include in following day

19. An application binds day boundaries as strings. List two aspects to verify with its connector.

Show hint

Trace the stated boundaries, precision, and applicable offset separately.

Show worked solution

Verify that the connector sends values with the intended type and fractional precision, and that its session time-zone setting matches the documented TIMESTAMP policy. Also check the chosen business zone and allowed range. Run boundary cases in an isolated environment using the deployed driver.

Check your solution

  • Check type and precision
  • Check session time zone

20. A report orders only by event_at and paginates tied events. Explain the limitation and repair.

Show hint

Trace the stated boundaries, precision, and applicable offset separately.

Show worked solution

Equal timestamps have no guaranteed relative order, so pages can vary among tied rows even if the data is unchanged. Add the unique id as a final ordering key, such as ORDER BY event_at, id. This defines a deterministic sequence for the stated result.

Check your solution

  • Time ties are unordered
  • Add unique id to ORDER BY

Key takeaways

  • Define the temporal meaning and session context before selecting a type.
  • Adjacent half-open intervals avoid overlapping endpoints.
  • Test exact and fractional boundaries in the intended time zone.
  • Convert both local calendar endpoints under their applicable zone rules.
  • A DATETIME clock value alone does not identify an instant.
  • A unique tie-breaker makes equal-time ordering deterministic.

Official references