I'm using SQL Server 2008 R2. I have a table with lots of dates, some in the past, some in the future. What I would like to do would be to update them so the dates are the 'next' date, relative to today.
For example given the current date is '2014-02-09'
Current Value Desired Value
-------------------------------------------------
'2010-01-06' '2015-01-06' (Updated to 2015)
'2008-03-28' '2014-03-28' (Updated to 2014)
I'd need to account for dates on 29th of Feb, just to make this easier!
What is the best way to do this?
3条答案
按热度按时间35g0bw711#
You can determine who many years in the past the date is. Then add that number of years plus one to the date:
brqmpdu12#
This should work:
Demo
c8ib6hqw3#
untested:
This would be so much easier if SQL Server supported a simple age calculation :-)