Jump to content

[SOLVED] Interpreting 2 digit years


artacus

Recommended Posts

So I'm importing data from this really old system, circa 1985. So of course it has 2 digit years for all of the dates.

 

I'm using mysql's STR_TO_DATE() to convert these to dates, but the default is to interpret any 00 - 69 as 2000 - 2069 ... not what I need for birthdays. Now its easy enough to subtract 100 years for anyone born before today. But is there a variable I can set at the connection level, to change how it interprets 2 digit years? I'd like not to have to change the setting for the whole server.

Link to comment
Share on other sites

The manual is pretty unambiguous .. it doesn't mention any settings that can be altered.

 

If it's a once-off import, why not just do it the easy way?  I don't quite get what you mean by "subtract 100 years for anyone born before today", but it's simple enough to insert "19" in front of each year before calling str_to_date().

Link to comment
Share on other sites

I'm positive that I read somewhere that you could change where mysql interprets a 2 digit year, at least at the server level. But I can't for the life of me find it now.

 

I don't quite get what you mean by "subtract 100 years for anyone born before today"

So if John Doe was born Jun 1, 66 his bday would read 060166, mysql will interpret this as 06/01/2066. So you have to subtract 100 years. The problem is there are lots of other dates in this extract (hire date, termination date, etc.) So prepending 19 to all of the years would not work there. And again some employees have been here pre 1970. So the easiest way to fix it all would be to just tell mysql to interpret anything above 08 as 1900's and anything below as 2000's.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.