Click here to Skip to main content
15,891,529 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
how to change month from date.
Ex: i have
Date: 22/02/2013 12:00:00 AM

from this date month value is :02
i have to replace this month with 05
now my date becomes : 22/05/2013 12:00:00 AM

how to do this in stored procedure ?
i have try this..
set @Month_From_Date = datepart(month,@Date)   --here i have take month from date(02)
 set @Month_From_Date =@Month_Value  --(month_value : 05 place in month_From_Date variable)


now @Month_From_Date contains (05).this value i have to put in date(in place of 02 in my example)

how to do this?
Posted
Updated 19-Feb-13 18:58pm
v2
Comments
Sergey Alexandrovich Kryukov 20-Feb-13 1:07am    
How is this related to C# or ASP.NET?
—SA

Hi dear,
Use SQL DateADD() function :

SQL
SELECT DATEADD(month, 1, '2006-08-30');


Look into the following link....


http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=156136[^]
 
Share this answer
 
v2
Comments
Member 9511889 20-Feb-13 1:05am    
i have to not add or substract month ,i have to take month which user select,this month is stored in month_value variable.
Try below
SQL
select  replace( '22/02/2013 12:00:00 AM',substring('22/02/2013 12:00:00 AM',4,2),'05')
 
Share this answer
 
v2
also cab try


select replace( '22/02/2013 12:00:00 AM',substring('22/02/2013 12:00:00 AM',charindex('/','22/02/2013 12:00:00 AM')+1,2),'05')


take '22/02/2013 12:00:00 AM' in variable
 
Share this answer
 
Comments
uspatel 20-Feb-13 2:31am    
Do not post you solution each time as new.Please update Old one.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900