Repository navigation
Backlog
Labels
Milestone
Description
What happens today
Each date producer has its own form (src/functions/date.js, src/expression/convert.js). NOW and CURRENT_DATE follow alasql.options.dateAsString, DATE always returns a Date, CAST formats text through structuredDate with a two-digit year, and a DATE column stores whatever it is given.
alasql('SELECT VALUE NOW()'); // '2026-11-26 10:38:16.449'
alasql('SELECT VALUE DATE("2024-01-02")'); // a Date object
alasql('SELECT VALUE CAST("2020-01-02" AS DATE)'); // '20.01.02'
alasql('SELECT VALUE NOW() > DATE("2020-01-01")'); // falseWhat to change
- Add
toDate(value, type)to the conversion module of Convert values for a typed column in one function, used by every write into a table #2659. It reads aDate, ISO text (YYYY-MM-DD,YYYY-MM-DD HH:MM:SS[.SSS], withTor a space) and a number in the formYYYYMMDDorYYYYMMDDhhmmss. An impossible date such as1994-02-30is an error that names the value. NULL gives NULL. toDatereturns one form per type, chosen byalasql.options.dateAsString. Withtrue(the default) aDATEisYYYY-MM-DDand aDATETIMEorTIMESTAMPisYYYY-MM-DD HH:MM:SS.SSS, in local time asNOWgives it today. Withfalseevery one is aDateobject.NOW,GETDATE,CURRENT_TIMESTAMP,CURRENT_DATE,DATE,CASTandCONVERTto a date type, and the write into aDATEorDATETIMEcolumn, all calltoDate. TheCONVERTstyles (CONVERT(STRING, d, 102)and the others) keep formatting text as today.- Date functions (
DATEDIFF,DATEADD,YEARand the others) accept both forms, as they do now throughnewDate. - Add the rule
dateValuesto Rules that differ between dialects become named rules chosen when a statement is compiled #3170 with the valuesiso(the new default) andv4. Withv4each producer keeps its 4.x form. Add it toalasql/dialect/v4.
What stays the same
NOW()andCURRENT_DATE()give the same text as before.- With
dateAsString: falsethey giveDateobjects as before. - With
alasql/dialect/v4every date producer gives its 4.x value. - In the default,
DATE(...)returns text,CASTto a date type returns ISO text or an error, and aDATEcolumn stores ISO text.
Done when
- A new test file named after this issue checks every producer above with
dateAsStringtrueandfalse, thatNOW() > DATE('2020-01-01')is true in both, thatCAST('1994-02-30' AS DATE)throws, thatCAST(20200102 AS DATE)is2020-01-02, and the 4.x values withalasql/dialect/v4. - The dialect test against SQLite gets date cases (
DATE('2020-01-02'), comparisons andORDER BYon ISO text,MAXover a date column). - The full test suite and the CI checks (dialect test, parity check, run-state check, binding check) pass, and the pull request lists every parity difference.
Fixes
Fixes #673, #2804, #1627, #2853.
Activity