N004-M4 Tier 1 · Foundations · medium

Return it as a calendar date

Part of Literal Values, Data Types, and Type Casting in SQL

The problem

Streamhub's product team is setting up the launch schedule for a new release. The go-live date is stored as the text string '2024-09-01' in the project management system.

Write a query to return it as a calendar date.

Output:

  • A single row with one column, launch_date, typed as a date.

Run previews · Check grades

Write a query, then run it to see results here.

Worked solution Try it yourself first
Solution query
SELECT
  CAST('2024-09-01' AS date) AS launch_date

The shape

CAST('2024-09-01' AS date) is the standard-SQL spelling of the same conversion the :: operator performs. It takes the quoted launch date and returns it as a real date value the schedule system can compare and order against other dates.

Clause by clause

  • CAST('2024-09-01' AS date) reads the text literal on the left, parses it as a date in the YYYY-MM-DD format PostgreSQL recognises, and returns the corresponding date value. The function-call shape is explicit: the value goes inside the parens, the keyword AS separates it from the target type, and the type name closes the expression.
  • AS launch_date labels the output column. The first AS belongs to the cast (it names the target type); this second AS belongs to the column alias. They're the same keyword doing two different jobs in the same statement.

Why this and not '2024-09-01'::date

Both produce identical results. CAST('2024-09-01' AS date) is the standard SQL form — defined by the SQL specification, portable to MySQL, SQL Server, Oracle, and every other major database. '2024-09-01'::date is the PostgreSQL-specific shorthand: shorter to type, but specific to this engine.

The choice is stylistic, and most PostgreSQL codebases mix the two. The cast form reads more naturally inside a longer expression. The :: form is cleaner for short inline casts. What doesn't change between them is the parsing requirement: the text has to be a format PostgreSQL recognises as a date.

The trap

The trap isn't the cast itself. It's assuming the cast handles any date-looking string. PostgreSQL is strict about the format it accepts. '09/01/2024' is ambiguous: September 1st or January 9th? PostgreSQL won't guess based on locale. If the project management system delivers dates in a non-YYYY-MM-DD form, the cast either errors or, in some formats, silently parses to the wrong day. Inspect the source format first and confirm the cast produces the date the prompt actually means.

You practiced converting text to a date — same outcome as the :: cast. Both CAST(... AS date) and '...'::date are valid; the choice is stylistic, not behavioral.

How you actually get good at SQL

Reading explains SQL. Writing it, over and over with instant feedback, is what makes you fluent.

That's the whole SQLMaxx loop: 600+ real problems, instant AI feedback, mastery you can actually see, and spaced review that won't let you forget.

A stack of SQL practice problem cards, the top card showing an employees table.
615 problems · 66 concepts

Real problems. Not toy examples.

615 hand-built problems spanning all 66 concepts, from basic SELECTs to window functions, built on real schemas and real business questions, the kind you'll actually get asked on the job. Enough reps to make SQL automatic.

A retro computer showing a SQL query marked correct with a green checkmark.
Instant AI feedback

Write a query. Know if it's right in one second.

No copying an answer and hoping it clicked. The AI grader checks your real query against real data, catches exactly what's wrong, and explains the fix in plain English, like a senior analyst reading over your shoulder on every problem.

A circular mastery progress dial filling from blue to green, the SQLMaxx diamond at its center.
Mastery tracking

Stop guessing whether you actually know it.

SQLMaxx tracks every concept and shows you what you've mastered and what's still shaky. Your skills fill in one concept at a time, so 'I think I get joins' becomes something you can prove.

A SQL query editor circled by a blue return arrow with a clock, scheduled to come back for review.
Spaced review

Learn it once. Keep it for good.

Most of what you learn this week fades by next week. So when a concept comes due for review, SQLMaxx hands you a fresh problem to solve from a blank editor, not a flashcard to re-read. A research-backed spaced-repetition algorithm (FSRS) times each return for right before you'd forget, so your SQL is still there months later, when the interview or the job actually needs it.

Practice, feedback, mastery, review. That's the loop that turns reading into real skill.

Start free

No account, no credit card. Start solving in under a minute.