Transact-SQL: Date-Related Queries (featured article)

Today we’re featuring an article from mult-gold-medal winner of the T-SQL Guru competition, multi-winner of the MCC award, and TechNet Wiki Community Council member, Naomi N:

Naomi N’s Profile

Naomi  N's avatar 

Naomi’s Blog


Thank you to Naomi for providing this great resource:

 T-SQL: Date-Related Queries


Here is an excerpt from the article:


Finding Day Number from the Beginning of the Year

I want to start with this simple question that was posted today (May 31, 2013) – how to find today’s date day number from the beginning of the year.

This is my solution and a bit of explanation at the end

DECLARE @YearStart DATE = dateadd (
    ,datediff(year, '19000101', @curDate)
SELECT datediff(day, @YearStart, @curDate) + 1 AS [Number of Days from the Year Start]






Thanks again to Naomi!


Check out the full article here:

T-SQL: Date-Related Queries


– User Ed

Comments (1)

  1. Computers Today (part 1 of 6)…/computers-today.aspx


    CS SPOTLIGHT: Girls in computer programming… why it matters!!!…/cs-spotlight-girls-in-computer-programming-why-it-matters.aspx

    Computational Thinking – Videos & Papers by Jeannette Wing…/computational-thinking-videos-amp-papers-by-jeannette-wing.aspx