INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

How to convert string DD-MMM-YY date to Date format in SQL.

How to convert string DD-MMM-YY date to Date format in SQL.

(OP)
Hello,
How to convert string DD-MMM-YY date to YYYY-MM-DD Date format in SQL?
Sample
'17-Jun-49' --> 1949-06-17
Thanks for the help.

RE: How to convert string DD-MMM-YY date to Date format in SQL.

Well, SELECT CONVERT(DATE,'17-Jun-49') returns
2049-06-17

... you would need to adjust accordingly.

Just my $.02

"What the captain doesn't realize is that we've secretly replaced his Dilithium Crystals with new Folger's Crystals."

--Greg

RE: How to convert string DD-MMM-YY date to Date format in SQL.

(OP)
Thanks Greg but My date year is 1949 not the 2049 (This is birth date field)

RE: How to convert string DD-MMM-YY date to Date format in SQL.

CODE

SELECT CONVERT(DATE,LEFT('17-Jun-49',7)+'19'+RIGHT('17-Jun-49',2)) 
but this will bring some more questions?
what is the border where you should start to add 2000 ->17 or 16 or...?

Borislav Borissov
VFP9 SP2, SQL Server

RE: How to convert string DD-MMM-YY date to Date format in SQL.

(OP)
Thanks Borislav
As I mentioned this is the birth date field. If we get someone birtdate in after 2000. Date will be something like 15-Jan-01.
then this approach wont work sad

RE: How to convert string DD-MMM-YY date to Date format in SQL.

So you’re saying with certainty that you have absoluely no birthdates in your table from 1900 through 1917?

Skip,

glassesJust traded in my OLD subtlety...
for a NUance!tongue

RE: How to convert string DD-MMM-YY date to Date format in SQL.

(OP)
Yes there is no birthdates in your table from 1900 through 1917.

RE: How to convert string DD-MMM-YY date to Date format in SQL.

You'll have to decide for a turnover year, the simplest rule is to go down 100 years if the date is in the future. But whatever birthdays are in your data, if they are from employees, none of them should be below age 16, perhaps, so you can also be quite sure 12 would mean 1912 instead of 2012. Then also, anyone beyond age 65 would not fit in with such a birth date today. So you may also use that to find invalid data not fitting the expected age range.

Find some cut offs like that and then you have your conversion.

In the simplest case any converted date must be a past date:

CODE

SELECT field, CASE WHEN CONVERT(DATE,field)>getdate() THEN DateAdd(year,-100,CONVERT(DATE,field)) ELSE CONVERT(DATE,field) END as theDate FROM yourtable 

Bye, Olaf.

RE: How to convert string DD-MMM-YY date to Date format in SQL.

'Tis the return of the Y2K bug. Still biting, 17 years later. :D

Just my $.02

"What the captain doesn't realize is that we've secretly replaced his Dilithium Crystals with new Folger's Crystals."

--Greg

RE: How to convert string DD-MMM-YY date to Date format in SQL.

(OP)
Thanks Olaf/Greg/Borislav/Skip.
It works now. :)

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close