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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Same day and month only

Status
Not open for further replies.

coolstrike23

Technical User
Feb 1, 2011
12
AU
Hi , I would like to return a date based on today's date. Only the day and month should be same with yeAr part replaced by a field. On 3rd July date returned should be 03/07/"oeshdt.yr".

I have tried cast(datepart(dd,getdate())+'/'+datepart(mm,getdate())+'/'+oeshdt.yr ) as datetime resulting in error converting '/'.

Appreciate your help.

CS
 
Code:
DECLARE @Today datetime
SET @Today = DATEADD(dd, 0, DATEDIFF(dd, 0, GETDATE()))
SELECT @Today 

DECLARE @Test TABLE (MyYear int)
INSERT INTO @Test VALUES(2009)
INSERT INTO @Test VALUES(2010)
INSERT INTO @Test VALUES(2011)
INSERT INTO @Test VALUES(2012)
INSERT INTO @Test VALUES(2013)


SELECT DateAdd(yy, MyYear-YEAR(@Today), @Today) AS Test
FROM @Test

Borislav Borissov
VFP9 SP2, SQL Server
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top