aspose file tools*
The moose likes JDBC and the fly likes changing year from yy to yyyy Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "changing year from yy to yyyy" Watch "changing year from yy to yyyy" New topic
Author

changing year from yy to yyyy

Mike Anna
Ranch Hand

Joined: Jul 08, 2007
Posts: 117
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

Joined: Feb 12, 2009
Posts: 133
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

Joined: Oct 27, 2005
Posts: 19670
    
  18

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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Mike Anna
Ranch Hand

Joined: Jul 08, 2007
Posts: 117
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

Joined: Feb 12, 2009
Posts: 133
How about this:

Mike Anna
Ranch Hand

Joined: Jul 08, 2007
Posts: 117
Hey thanks a ton John,
just had to add :


thanks again.

cheers...
MA
John Bengler
Ranch Hand

Joined: Feb 12, 2009
Posts: 133
You're Welcome!

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: changing year from yy to yyyy