-2

Why does

select cast('''1900-01-01''' as datetime)

fail in SQL Server 2005 ?

It's show error message :

Conversion failed when converting datetime from character string.

Thanks.

Steve Kass
  • 7,144
  • 20
  • 26
Iswanto San
  • 18,263
  • 13
  • 58
  • 79
  • Does this code work? `SELECT CAST('19000101' AS DATETIME)` - no dashes in the string representing the date. – marc_s May 11 '12 at 05:01

1 Answers1

0

you have an invalid parameter. It should be

cast('1900-01-01' as datetime)

For more info See Here: CAST and CONVERT and How to convert from string to datetime?

Iswanto San
  • 18,263
  • 13
  • 58
  • 79
John Woo
  • 258,903
  • 69
  • 498
  • 492
  • Sorry, I mean cast ('''1900-01-01''' as datetime). It doesn't work – Iswanto San May 11 '12 at 05:08
  • The 12-character string you are trying to convert begins and ends with apostrophes doesn't represent a valid datetime. Why should it work? (editing the original question to match your comment here). – Steve Kass May 11 '12 at 05:11
  • http://stackoverflow.com/questions/4794028/ms-sql-compare-dates – John Woo May 11 '12 at 07:53