472,147 Members | 1,254 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,147 software developers and data experts.

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 7261
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
reply views Thread by Saiars | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.