Skip to content

Comments

bug(tsql): fix datepart handling when part is quoted#6934

Merged
georgesittas merged 1 commit intotobymao:mainfrom
foundational-io:foundational/fix-tsql-datepart
Feb 3, 2026
Merged

bug(tsql): fix datepart handling when part is quoted#6934
georgesittas merged 1 commit intotobymao:mainfrom
foundational-io:foundational/fix-tsql-datepart

Conversation

@flow3d
Copy link
Contributor

@flow3d flow3d commented Feb 2, 2026

Previous discussion here
Summary - while this doesn't seem valid, this is a legitimate TSQL syntax (escaping date parts).
It's already supported in dateadd & datediff, but was missing from datepart.

Validated here as well with select datepart("dd",'2025-12-13') on SQL Server 2022

-- more details
trust me, I don't like this being a valid syntax neither, but it is :)

select @reportdate = datepart("dd",getdate())

the above is a valid TSQL syntax.
Also - note that you guys already support this syntax in other date functions:

select dateadd("dd", -DAY(getdate()), DATEADD("mm", 0, detdate()))

is parsed into:

[Select(
   expressions=[
     DateAdd(
       this=DateAdd(
         this=Anonymous(this=detdate),
         expression=Literal(this=0, is_string=False),
         unit=Var(this=MONTH)),
       expression=Neg(
         this=Day(
           this=CurrentTimestamp())),
       unit=Var(this=DAY))])]

@flow3d flow3d changed the title tsql: fix datepart when part is quoted bug(tsql): fix datepart handling when part is quoted Feb 2, 2026
@georgesittas georgesittas merged commit 22a0db7 into tobymao:main Feb 3, 2026
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants