×
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!
  • Students Click Here

*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.

Students Click Here

Jobs

str_to_date for dates in other languages

str_to_date for dates in other languages

str_to_date for dates in other languages

(OP)
Not really used to getting knee deep in complex queries, but need to build a trigger to take a date in a format like "10 de febrero de 2014" into a usable date format. It seems the str_to_date function will not recognize month names in anything other than the set language for lc_time_names global. The database configuration cannot really be changed as other tables and columns depend on it.

Anyone have any suggestions, on how to actually get it to work?

I'm going to add this to a trigger, so that when data is inserted by a different process it can convert the dates automatically and make them more searchable, and accionable since I need to have a cron check every so often when something has expired via these dates.

Any help is appreciated.

Current query if it helps. It currently returns Null since it cannot identify the spanish month name:

CODE --> mysql

SELECT STR_TO_DATE("10 de febrero de 2014","%d de %M de %Y") AS mydate; 

----------------------------------
Phil AKA Vacunita
----------------------------------
OS-ception: Running Linux on a Virtual Machine in Windows which itself is running in a Virtual Machine on Mac OSx.

Web & Tech

RE: str_to_date for dates in other languages

(OP)
Figured out how to actually modify it. It's not the cleanest, nor likely the most optimal way, but it works:

The starting date string is a bit more complex than what I had above, as it contains 2 dates not just 1, separated by a slash /.

CODE --> mysql

STR_TO_DATE(CONCAT(SUBSTRING_INDEX(TRIM(SUBSTRING_INDEX(fechas,"/",-1)),"de",1),(SELECT id FROM meses WHERE `name`= SUBSTRING_INDEX(TRIM(SUBSTRING_INDEX(SUBSTRING_INDEX(fechas,"/",-1),"de",-2)),"de",1)),SUBSTRING_INDEX(TRIM(SUBSTRING_INDEX(SUBSTRING_INDEX(fechas,"/",-1),"de",-2)),"de",-1)),"%e %m %Y") 

I created a table to hold the spanish names of the months, and then used that to convert the months to their correct number.

The trigger will need to run this before insert.

----------------------------------
Phil AKA Vacunita
----------------------------------
OS-ception: Running Linux on a Virtual Machine in Windows which itself is running in a Virtual Machine on Mac OSx.

Web & Tech

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!

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