• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

changing year from yy to yyyy

 
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How about this:

 
Mike Anna
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're Welcome!

 
The glass is neither half full or half empty. It is too big. But this tiny ad is just right:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic