truncated incorrect value
Question: I have a python code that displays a range of dates. In the code below I have
passed the dates in the select operation by casting the dates and using
STR_TO_DATE function. I want to know how a range of values with start and end
date can be passed in the query below. what i want to achieve is to give a
range of dates and the script should find those dates in the mysql table and
display the dates.The date column in mysql is varchar type.SO i need to
convert varchar to date and then use between operator to get range of
dates.Following is the code snippet:

    
    
    import MySQLdb
    import os,sys
    import datetime
    
    path="C:/Python27/"
    conn = MySQLdb.connect (host = "localhost",user = "root", passwd = "CIMIS",db = "cimis")
    c = conn.cursor()
    
    message = """select stationId,Date,hour,airTemperature from cimishourly where  Date between CAST((SELECT STR_TO_DATE('5/16/2011 ', '%c/%e/%Y')) AS DATE) and CAST((SELECT STR_TO_DATE('5/18/2011 ', '%c/%e/%Y')) AS  DATE)"""
    c.execute(message,)
    result=c.fetchall()
    for row in result:
        print(row)
    conn.commit()
    c.close()
    

the error message is:truncated incorrect date value '6/8/1982'


Answer: First off, **Please include your error in your question**. This makes it
easier for people to help you.

I'm gussing from the title that your trying to do something like:

    
    
    s = "string"
    l = ["list", "list2"]
    print(l + s)
    

That is incorrect. You can't add a variable of type string and a variable of
type list together.

If your trying to add your strings and list all into one string, use the
builtin python function `str()` to convert a list to a string, and then use
`.join` to join the strings.

    
    
    s = "string"
    l = ["list", "list2"]
    print(str(''.join(l)) + s)
    
    #output: listlist2string
    

If your trying to convert your strings into a list, use the builtin python
function `list()` which converts the string to a list:

    
    
    s = "string"
    l = ["list", "list2"]
    print(l + list(s))
    
    #output: ['list', 'list2', 's', 't', 'r', 'i', 'n', 'g']
    

Or, if your trying to add a string to every other string in your list, use
list comprehension:

    
    
    s = "string"
    l = ["list", "list2"]
    ls = [str(''.join(i)) + s for i in l]
    print(ls)
    
    #output :['liststring', 'list2string']
    

For more information on converting types in python, i reccomend reading:
<http://www.pitt.edu/~naraehan/python2/data_types_conversion.html>.

**EDIT** : After updating your title and posting the error message, I believe
that your problem stems from these lines: `(SELECT STR_TO_DATE('5/18/2011 ',
'%c/%e/%Y')`. which should be: `STR_TO_DATE('2011/5/18', '%Y-%m-%d')`.

