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)
 Prepare Date from Day and month Parameter

Author  Topic 

imranabdulaziz
Yak Posting Veteran

83 Posts

Posted - 2010-08-12 : 23:29:03
Hi all,
I am using sql server 2005.
I have month in Parameter and Day of Date in parameter. Now i have to generate date from these parameter
that is if day is 15 , month is 10 then it should be 15-10-2010.

Please suggest

pk_bohra
Master Smack Fu Yak Hacker

1182 Posts

Posted - 2010-08-13 : 00:17:40
It should give you idea to start with :

Declare @DayParam varchar(2)
Declare @MonthParam varchar(3)


Set @DayParam = 15
set @MonthParam = 10


Select convert(datetime,@DayParam + '-' + @MonthParam + '-' + cast(year(getdate()) as varchar(4)) ,105)


Regards,
Bohra

I am here to learn from Masters and help new bees in learning.
Go to Top of Page

Kokkula
Starting Member

41 Posts

Posted - 2010-08-13 : 01:42:41
Hello,

Try this....

DECLARE @Month INT
DECLARE @day INT
SET @Month = 10
SET @Day = 21

SELECT CAST(CAST(@Month AS NVARCHAR) + '/' + CAST(@Day AS NVARCHAR) + '/' + CAST(YEAR(GETDATE()) AS NVARCHAR) AS DATETIME)

Hope its helpful....


Pavan
Infosys Technologies Limited
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-08-13 : 10:30:11
Another method


DECLARE @Month INT
DECLARE @day INT
SET @Month = 10
SET @Day = 21

select dateadd(year,year(getdate())-1900,dateadd(month,@month-1,@day-1))


Madhivanan

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

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2010-08-13 : 11:21:03
Same question asked and answered here http://social.msdn.microsoft.com/Forums/en-US/transactsql/thread/d4f18b94-1052-4ead-852e-f74e876e3f71

SELECT DATEADD(MONTH, 12 * YEAR(GETDATE()) + @Month - 22801, @Day - 1)




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

- Advertisement -