MySQL Forums
Forum List  »  Newbie

Re: Help with cast and sql query
Posted by: Roland Bouman
Date: August 11, 2005 09:33AM

Karla, i guess the problem is that your data is still in the string format.

If you are using mysql >= 4.1.1, you can use

STR_TO_DATE(string,format)

For your example:

STR_TO_DATE(
CONCAT(
year
, month
, day
)
, CONCAT(
'%Y'
, '%c'
, '%e'
)
)


(I wrote a CONCAT for the format string so you can see what corresponds to what - its ok to write it as a single string: '%Y%m%e')

see the reference:

http://dev.mysql.com/doc/mysql/en/date-and-time-functions.html

for more details on format strings. Beware that the format strings are case-sensitive. In the format string I used here, Im assuming your year is four digit year, your month is a integer (months 1..12, not '01'..'12') and your days integers (day 1..31, not '01'..'31')

Options: ReplyQuote


Subject
Written By
Posted
August 11, 2005 09:12AM
Re: Help with cast and sql query
August 11, 2005 09:33AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.