Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Convert to Days

Author  Topic 

madscientist
Starting Member

30 Posts

Posted - 2007-12-04 : 19:35:04
Hi everyone.

In the HEADER table I have a column name BOOK_FLAG_DATE which has dates in the format:

7/6/2006 14:37:22

I want to convert the dates to just the number of days elapsed since that year began i.e. in this case 187.

Thank you for the help.

dinakar
Master Smack Fu Yak Hacker

2507 Posts

Posted - 2007-12-04 : 19:38:08
[code]
Declare @D Datetime , @D2 datetime
Set @d = '7/6/2006 14:37:22'

select datediff(dd, convert(varchar,Year(@d)) + '0101', @d )
[/code]

Dinakar Nethi
************************
Life is short. Enjoy it.
************************
http://weblogs.sqlteam.com/dinakar/
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-12-05 : 03:14:24
or

Declare @D Datetime , @D2 datetime
Set @d = '7/6/2006 14:37:22'
select datepart(dayofyear, convert(datetime,@d))


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -