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 2000 Forums
 Transact-SQL (2000)
 --Resolved -- Add year

Author  Topic 

rkalyani
Starting Member

30 Posts

Posted - 2009-07-02 : 15:56:10
I have to do a select with a date like this
'08/01' & current year.
I tried this
CONVERT(datetime, '01/02' + year(GetDate()), 103) but it is comes back with an error. I am not sure how to do this.



Thank you,
kal30

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-07-02 : 16:15:41
SELECT DATEADD(YEAR, @Year - 1900, '19000801')
SELECT DATEADD(YEAR, DATEDIFF(YEAR, 0, GETDATE()), '19000801')


Microsoft SQL Server MVP

N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-07-03 : 02:39:58
quote:
Originally posted by rkalyani

I have to do a select with a date like this
'08/01' & current year.
I tried this
CONVERT(datetime, '01/02' + year(GetDate()), 103) but it is comes back with an error. I am not sure how to do this.



Thank you,
kal30


That should be

select CONVERT(datetime, '01/02/' + cast(year(GetDate()) as char(4)), 103)

Madhivanan

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

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-07-03 : 02:44:20
Or
select CONVERT(datetime, '01/02/' + datename(year, GetDate()), 103)

or
SELECT DATEADD(YEAR, DATEDIFF(YEAR, 0, GETDATE()), '19000801')



Microsoft SQL Server MVP

N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page

rkalyani
Starting Member

30 Posts

Posted - 2009-07-03 : 11:30:46
Thank you so much. It works very well for me.

Thank you,
kal30
Go to Top of Page
   

- Advertisement -