Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DayofYear to actual date 2

Status
Not open for further replies.

VeryGoodGirl

Programmer
May 9, 2007
7
US
I am being passed the dayofyear (example: 169) and need to convert that into the actual date. I realize that I will need to be passed the year also. Does anyone know how to get date from dayofyear. Thank you!!!!
 
example
hardcoded

select dateadd(d,169,'20070101')

or not hardcoded which will work for this year only

select dateadd(d,169,dateadd(yy, datediff(yy, 0, getdate())+0, 0))

just add

dateadd(d,169,

to

dateadd(yy, datediff(yy, 0, getdate())+0, 0)



Denis The SQL Menace
--------------------
SQL Server Code,Tips and Tricks, Performance Tuning
SQLBlog.com
Google Interview Questions
 
Here is something you can make into a stored procedure or a function

Code:
declare @dayOfYear int
declare @year char(4)
set @dayOfYear = 169
set @year = 2007

select convert(datetime, @year + '-01-01') + @dayOfYear


[monkey][snake] <.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top