469,150 Members | 1,951 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,150 developers. It's quick & easy.

How to update the Year in a date field?

Hi All,
The AP clerks forgot to change the year from 2009 to 2010, so they did lots of data entry with invoice dates instead of 2010, they added 2009 and the date field looks like this "2009-01-16 00:00:00.000", is there a way to replace 2009 with 2010.

Please help me and thanks in advance,
[email deleted]
Mar 9 '10 #1
2 7179
5,000 Expert 4TB
Don't post your email again.
Mar 9 '10 #2
2,878 Expert 2GB
Try to do this if this is what you need:

Expand|Select|Wrap|Line Numbers
  2. select invoice_date, cast('2010' + right(convert(varchar(8), invoice_date,112),4)  as datetime) as new_invoice_date
  3. from YOURTABLE
  4. where year(invoice_date) = 2009
Make sure that this is what you want before updating your table.

Happy Coding!!!

~~ CK
Mar 10 '10 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

3 posts views Thread by Lapchien | last post: by
3 posts views Thread by Ray | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
1 post views Thread by Mortomer39 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.