Quantcast
Channel: MSDN Blogs
Viewing all articles
Browse latest Browse all 29128

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

$
0
0

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'
    );
 
SELECTdatediff(day, @YearStart, @curDate) + 1 AS[Number ofDays fromthe Year Start]

 

 

=====================

 

 

Thanks again to Naomi!

 

Check out the full article here:

T-SQL: Date-Related Queries

 

- User Ed


Viewing all articles
Browse latest Browse all 29128

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>