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 @curDate DATE = CURRENT_TIMESTAMP;
DECLARE @YearStart DATE = dateadd (
    year
    ,datediff(year, '19000101', @curDate)
    ,'19000101'
    );
 
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