Solved

Day of the year function in tsql

Posted on 2007-11-26
2
3,558 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
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 125 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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.

773 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