--- id: sql-dates title: "SQL Dates" category: "Database" status: "draft" verification_status: "conceptual" canonical_id: "" aliases: ["SQL Working With Dates", "SQL ๋‚ ์งœ"] duplicate_of: "" source_trust_level: "B" confidence_score: 0.88 created_at: 2026-07-04 updated_at: 2026-07-04 review_reason: "" merge_history: [] tags: ["sql", "database", "w3schools", "dates"] raw_sources: ["https://www.w3schools.com/sql/sql_dates.asp"] applied_in: [] github_commit: "" --- # [[SQL Dates]] ## ๐ŸŽฏ ํ•œ ์ค„ ํ†ต์ฐฐ (One-line insight) Matching a date literal against a datetime column silently returns nothing if the stored value carries a time component the literal doesn't โ€” the hardest part of SQL dates is format alignment, not date logic itself. [S1] ## ๐Ÿง  ํ•ต์‹ฌ ๊ฐœ๋… (Core concepts) - **The core difficulty** โ€” being sure the date format you insert/select matches the database column's format. [S1] - **MySQL date types** โ€” `DATE` (YYYY-MM-DD), `DATETIME`/`TIMESTAMP` (YYYY-MM-DD HH:MI:SS), `TIME` (HH:MI:SS), `YEAR` (YYYY or YY). [S1] - **SQL Server date types** โ€” `DATE`, `DATETIME`, `SMALLDATETIME`, `TIME`, `TIMESTAMP` (a unique number, not a date). [S1] ## ๐Ÿงฉ ์ถ”์ถœ๋œ ํŒจํ„ด (Extracted patterns) - **Time-component footgun** โ€” a WHERE clause like `OrderDate='2025-11-11'` matches rows when the column is pure `DATE`, but silently returns zero rows once the column stores a time component too (e.g. `2025-11-11 13:23:44`), because exact string/value equality no longer holds. [S1] - **Keep dates time-free unless necessary** โ€” the source explicitly recommends avoiding time-components in date columns to keep queries simple, unless the time is actually needed. [S1] ## ๐Ÿ“– ์„ธ๋ถ€ ๋‚ด์šฉ (Details) - Simple date match (works, no time component): `SELECT * FROM Orders WHERE OrderDate='2025-11-11'`. [S1] - Same query against a column that also stores time (returns NO rows, since exact match requires the time portion too): same query, different schema. [S1] ## โš–๏ธ ๋ชจ์ˆœ ๋ฐ ์—…๋ฐ์ดํŠธ (Contradictions & updates) ์†Œ์Šค์—์„œ ๋ชจ์ˆœ๋˜๋Š” ์ •๋ณด๋Š” ๋ฐœ๊ฒฌ๋˜์ง€ ์•Š์Œ. ๋‹ค๋งŒ "๋™์ผํ•ด ๋ณด์ด๋Š” ์ฟผ๋ฆฌ๊ฐ€ ์Šคํ‚ค๋งˆ์— ๋”ฐ๋ผ ๊ฒฐ๊ณผ๊ฐ€ ์™„์ „ํžˆ ๋‹ฌ๋ผ์ง„๋‹ค"๋Š” ์ ์ด ํ•ต์‹ฌ ๊ฒฝ๊ณ ๋กœ ์ œ์‹œ๋จ. [S1] ## ๐Ÿ› ๏ธ ์ ์šฉ ์‚ฌ๋ก€ (Applied in summary) ํ˜„์žฌ ๋ฐœ๊ฒฌ๋œ ์‹ค์ œ ์ ์šฉ ์‚ฌ๋ก€๊ฐ€ ์—†์Šต๋‹ˆ๋‹ค โ€” "์ฟผ๋ฆฌ๊ฐ€ ์•„๋ฌด ๊ฒฐ๊ณผ๋„ ์•ˆ ์ค€๋‹ค"๋Š” ํ”ํ•œ ๋ฒ„๊ทธ์˜ ์›์ธ์ด ๋‚ ์งœ/์‹œ๊ฐ„ ํฌ๋งท ๋ถˆ์ผ์น˜์ธ ๊ฒฝ์šฐ๊ฐ€ ๋งŽ๋‹ค. [S1] ## ๐Ÿ’ป ์ฝ”๋“œ ํŒจํ„ด (Code patterns) Exact date match, no time component (SQL): ```sql SELECT * FROM Orders WHERE OrderDate='2025-11-11'; ``` ## โœ… ๊ฒ€์ฆ ์ƒํƒœ ๋ฐ ์‹ ๋ขฐ๋„ - **์ƒํƒœ:** draft - **๊ฒ€์ฆ ๋‹จ๊ณ„:** conceptual - **์ถœ์ฒ˜ ์‹ ๋ขฐ๋„:** B (W3Schools โ€” widely used educational reference, not a primary standards body) - **์‹ ๋ขฐ ์ ์ˆ˜:** 0.88 - **์ค‘๋ณต ๊ฒ€์‚ฌ ๊ฒฐ๊ณผ:** ์‹ ๊ทœ ์ƒ์„ฑ (New discovery) ## ๐Ÿ”— ์ง€์‹ ๊ทธ๋ž˜ํ”„ (Knowledge Graph) - **์ƒ์œ„/๋ฃจํŠธ:** [[SQL Tutorial]] - **๊ด€๋ จ ๊ฐœ๋…:** [[SQL Between]], [[SQL Data Types]], [[SQL Where]] - **์ฐธ์กฐ ๋งฅ๋ฝ:** ๋‚ ์งœ/์‹œ๊ฐ„ ์ปฌ๋Ÿผ์„ ๋‹ค๋ฃจ๋Š” ๋ชจ๋“  ์ฟผ๋ฆฌ์—์„œ ํฌ๋งท ๋ถˆ์ผ์น˜ ๋ฒ„๊ทธ๋ฅผ ์˜ˆ๋ฐฉํ•˜๊ธฐ ์œ„ํ•ด ์ฐธ์กฐ. ## ๐Ÿ“š ์ถœ์ฒ˜ (Sources) - [S1] W3Schools โ€” SQL Working With Dates โ€” https://www.w3schools.com/sql/sql_dates.asp ## ๐Ÿ“ ๋ณ€๊ฒฝ ์ด๋ ฅ (Change history) - 2026-07-04: Initial draft synthesized from the W3Schools "SQL Working With Dates" page (Astra wiki-curation, P-Reinforce v3.1 format).