Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

changing year from yy to yyyy

 
Mike Anna
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have a table here which has values of year in the yy format. The column itself is an int.
Now, there is a need to convert the values into yyyy format. So for ex. 12 will become 2012. 1 will become 2001.
I looked at convert and decode functions, but I am not sure if that will help. Could you please guide me on how I could do this on mysql ?


thanks,
MA
 
John Bengler
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Mike,

if you don't have values before the year 2000 in it you could just add 2000 to your int value...


If you have also values for years of the last millenium it willbe a little more difficult.


John
 
Rob Spoor
Sheriff
Pie
Posts: 20529
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you do have years from the 1900s you can use the following:
The switch is up to you, and you will run into problems if you have a century worth of data. Then again, if this application still runs in 70 years then you will have archived / deleted older data and the switch can be increased.
 
Mike Anna
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot for the reply. I just have the years from 2000 onwards, thankfully.
I just couldnt think it was as simple as adding 2000 to the values. lol
Since this change will go up a sql which is bound to be run again and again. I just wanted to be sure that I do not end up adding 2000 everytime the query is run.
I am a little lost on this simple query. I was thinking in the lines of the below, but I am obviously wrong :


Could you please help me here.

thanks in advance for your time
 
John Bengler
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How about this:

 
Mike Anna
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey thanks a ton John,
just had to add :


thanks again.

cheers...
MA
 
John Bengler
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're Welcome!

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic