Date problem | SQL Server Performance Forums

SQL Server Performance Forum – Threads Archive

Date problem

declare @Bdate datetime
declare @d1 datetime
set @Bdate = ’14/12/2005′
set @d1 = ’20/12/2005′ SELECT DATEDIFF(d, @Bdate, @d1) AS days, DATEDIFF(wk, @Bdate, @d1) AS weeks, DATEDIFF(m, @Bdate, @d1) AS months Its giving the following error "The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value." Plz give me the solution With Regards
Aruna Mathew

the most failsafe way to convert strings to date time is to use the YYYY-MM-DD format, in your case, you probably installed the OS or SQL with one of the American date formats, MM/DD/YYYY instead of the european DD/MM/YYYY
Also read this Madhivanan Failing to plan is Planning to fail