Board index » delphi » Dates in SQL statements

Dates in SQL statements

How can I hard code a date in an SQL statement to be used in TQUERYSQL
property?
e.g: SELECT * FROM CUST WHERE
            ENTRY_DATE = 21/5/1995

Have tried quotes, double quotes etc but still get error.
A parameterised query seems to work.

reply to: mbro...@england.com

 

Re:Dates in SQL statements


Quote
Mike Browne wrote in message <35ad05c...@news.thefree.net>...
>How can I hard code a date in an SQL statement to be used in TQUERYSQL
>property?
>e.g: SELECT * FROM CUST WHERE
>            ENTRY_DATE = 21/5/1995

Dates are database dependant.

For Local SQL, dates must be in US format (i.e. month/day/year).

    SELECT *
    FROM CUST
    WHERE   ENTRY_DATE = '5/21/1995'

If it was an Oracle db, you may specify the date format.
    SELECT *
    FROM CUST
    WHERE   ENTRY_DATE = To_Date('21/5/1995', 'DD/MM/YYYY')

I don't know how dates are specified in any other db's besides these.

        -- Kirk

Re:Dates in SQL statements


 If i remember correctly, there are a few standard formats that all
sql92 compliant db must be able to decode. I think that one of them
for the dates is 'yyyy-mm-dd'. Anyway, it has worked for all db that i
have tried it on (db2, sql anywhere, dbase, access).

Francis

Quote

>Mike Browne wrote in message <35ad05c...@news.thefree.net>...
>>How can I hard code a date in an SQL statement to be used in TQUERYSQL
>>property?
>>e.g: SELECT * FROM CUST WHERE
>>            ENTRY_DATE = 21/5/1995

>Dates are database dependant.

>For Local SQL, dates must be in US format (i.e. month/day/year).

>    SELECT *
>    FROM CUST
>    WHERE   ENTRY_DATE = '5/21/1995'

>If it was an Oracle db, you may specify the date format.
>    SELECT *
>    FROM CUST
>    WHERE   ENTRY_DATE = To_Date('21/5/1995', 'DD/MM/YYYY')

>I don't know how dates are specified in any other db's besides these.

>        -- Kirk

Other Threads