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
 General SQL Server Forums
 New to SQL Server Programming
 How to make a date

Author  Topic 

yaman
Posting Yak Master

213 Posts

Posted - 2008-07-14 : 10:33:23
Sir

I have a year

I want to create a date from Year Like i have
YEAR = 2007
and i want to make a date Like 01-01-2008

pls help me out

Yaman

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-07-14 : 10:35:28
SELECT DATEADD(YEAR, @Year - 1900, '19000101')



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2008-07-14 : 10:35:48
[code]declare @year int

select @year = 2007

select dateadd(year, @year + 1 - 1900, 0)[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2008-07-14 : 10:36:20
20 secs slower
and wrong answer

KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-07-14 : 10:41:42
<<
and i want to make a date Like 01-01-2008
>>

If you want first day of next year,

select dateadd(year, @year+1 - 1900, 0)


Madhivanan

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

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-07-14 : 10:43:33
Plus 1 minus 1899 equals to -1899.



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page
   

- Advertisement -