Difference between Day and DayOfYear DateParts in SQL

Rohit 226 Reputation points
2023-09-22T09:14:47.8+00:00

Hello,

What is the difference between day and dayofyear dateparts in SQL Datediff function? both seems to yield the same result? shouldn't dayofyear value in case of diff always be less than 365 ?

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
13,785 questions
0 comments No comments
{count} votes

Accepted answer
  1. Nandan Hegde 32,336 Reputation points MVP
    2023-09-22T09:17:26+00:00

    Hey,

    Yes it is the same effect for DATEDIFF(). For an arithmatetic function like DATEDIFF(), it will have the same result, as the math is still taking into account the same unit: whether it's for day or dayofyear they are both still in days.

    Similar thread :

    https://dba.stackexchange.com/questions/18065/sql-server-datediff-hows-dayofyear-different-from-day

    1 person found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Olaf Helper 44,501 Reputation points
    2023-09-22T09:19:49.5533333+00:00

    both seems to yield the same result?

    ??? Run

    select datepart(day, getdate()), datepart(dayofyear, getdate())
    
    

    Returns 22 and 265; for me it's very different.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.