1

Hi I have a database that lists expiration dates etc...

5-22-2012
5-22-2012
5-22-2012
5-22-2012

but some came out like

5-22-1912
5-22-1912
5-22-1912

is there a way to REPLACE just those years at the end of my columns?

3
  • its DATE - I had to repair our database somehow a 9th of our patients turned up with these invalid expiration dates Commented Jul 24, 2011 at 7:18
  • 2
    As to why and how these values got into the table in the first place, check the insert procedure (form, webpage, whatever). Probably it doesn't have to do with MySQL as default MySQL behaviour is "# Dates containing two-digit year values are ambiguous because the century is unknown. MySQL interprets two-digit year values using the following rules: * Year values in the range 00-69 are converted to 2000-2069. * Year values in the range 70-99 are converted to 1970-1999. ". Commented Jul 24, 2011 at 7:28
  • (from: dev.mysql.com/doc/refman/5.1/en/datetime.html ) Commented Jul 24, 2011 at 7:28

2 Answers 2

4

If field is DATE type:

--- Add 100 years when date is before 1940

UPDATE TableX
SET expirationDate = expirationDate + INTERVAL 100 YEAR
WHERE expirationDate < '1940-01-01'
Sign up to request clarification or add additional context in comments.

Comments

1
UPDATE table 
SET thiscolumn = CONCAT(month(thiscolumn),'-', day(thiscolumn),'-2012')
WHERE year(thiscolumn) = '1912';

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.