to_date in SQL Server 2005

后端 未结 2 896
刺人心
刺人心 2020-12-22 00:07

Does any one know how I would have to change the following to work with ms sql?

WHERE registrationDate between to_date (\'2003/01/01\', \'yyyy/mm/dd\')
AND t         


        
2条回答
  •  天命终不由人
    2020-12-22 00:49

    Use:

    WHERE registrationdate BETWEEN '01/01/2003' AND '12/31/2003'
    

    ...but as gbn pointed out, to be locale safe - use:

    WHERE registrationdate BETWEEN '20030101' AND '20031231'
    

    SQL Server will perform implicit conversion of the string into a date, providing it's a supported format. Explicit conversion is when you have to use CAST or CONVERT to change the data type.

    When converting '01/01/2003' to a DATETIME, the time portion will be 00:00:00 because it wasn't specified.

提交回复
热议问题