Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Day of the year function in tsql

Posted on 2007-11-26
2
Medium Priority
?
3,581 Views
Last Modified: 2008-02-01
is there a way to determine the day of the year given a date in sql server.  For example, 1/1/2007 would return 1, 2/1/2007 would return 32....

Thanks,
ptran
0
Comment
Question by:ptran2000
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 29

Expert Comment

by:QPR
ID: 20354704
you could use datediff to calculate the number of days between 1/1/2007 and the supplied date.
If not 2007 then take the year part of the supplied date and convert that to 1/1/yyyy
then use this to calculate
0
 
LVL 7

Accepted Solution

by:
macentrap earned 500 total points
ID: 20354764
SELECT DATEPART(y, GETDATE()) AS 'Day of the Year'

SELECT DATEPART(y, '2007-12-02') AS 'Day of the Year'
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
This month, Experts Exchange sat down with resident SQL expert, Jim Horn, for an in-depth look into the makings of a successful career in SQL.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

609 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question