September 16, 2003 at 2:16 pm
Does anybody know how to convert "2003226"
It means 226the day of the year. I need to convert it to mm/dd/yyyy. Any help is greatly appreciated.
September 16, 2003 at 2:52 pm
Try something like this:
declare @jdate char(7)
set @jdate = '2003226'
select convert(char(10),dateadd(day,1,datediff(day,1,substring(@jdate,1,4) + '-01-01')+
datediff(day,1,cast(substring(@jdate,5,7) as int))), 101)
Gregory Larsen, DBA
If you looking for SQL Server Examples check out my website at http://www.geocities.com/sqlserverexamples
Gregory A. Larsen, MVP
September 16, 2003 at 3:00 pm
Sorry, I made that calculation do a lot more work then it needed to. Here is one with less math:
select convert(char(10),
dateadd(day,cast(substring(@jdate,5,7) as int)-1,cast(substring(@jdate,1,4) + '-01-01' as datetime))
, 101)
Gregory Larsen, DBA
If you looking for SQL Server Examples check out my website at http://www.geocities.com/sqlserverexamples
Gregory A. Larsen, MVP
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply