Click here to Skip to main content
15,891,828 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I wanted to display following date value replacing current year with the next year.

2012-07-01 must be changed to 2013-07-01.

Here year part alone to be changed but not the date and month

Pls I need help
Posted
Updated 13-Mar-13 3:21am
v3
Comments
[no name] 13-Mar-13 8:59am    
Help with what? How to get the current year? How to add 1 to the previous year value? How to display the current year? Please improve your question.
Biodude Basava 13-Mar-13 9:07am    
2012-07-01 must be changed to 2013-07-01.
Here year part alone to be changed but not the date and month
[no name] 13-Mar-13 9:19am    
Okay and? What have you tried? Did you try using the YEAR function? What about DATEPART?

Use DateAdd[^] with year as the Datepart parameter.

DateAdd(year,1,YourDateColumnName)



To change an existing date to the next year while keeping the month and day the same:
UPDATE yourtablename SET quarter_startdate=DATEADD(year,1,quarter_startdate);
 
Share this answer
 
v2
If it is display that you want:

SQL
SELECT 
    DateAdd(year,1,TableName.dateColumnName) AS [YearAddedDate]
FROM
   TableName

Obviously you'll need to amend if you want to update the table or add criteria. More obviously you'll need to supply the correct values for the italicised names.
 
Share this answer
 
Comments
Biodude Basava 13-Mar-13 9:29am    
hey folks thanks a lot it works perfectly. :)
Keith Barrow 13-Mar-13 9:34am    
No problem.
Biodude Basava 13-Mar-13 10:13am    
got another question....
year should automatically take the currentyear..??
Keith Barrow 13-Mar-13 10:23am    
Can't answer that for you, depends what you want to do.
Biodude Basava 13-Mar-13 10:32am    
scenario is like..
i have the column quarter_startdate='2012-07-01'.
now i have to write an update query which takes the current year and month and date are fixed.
????

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