Skip to main content
edited tags
Link
Colin 't Hart
  • 9.4k
  • 15
  • 36
  • 44
Source Link
Hrvoje
  • 103
  • 3

MS SQL -Date and Time Style conversion problem

I need to convert Date and Time Style from USA format to German and than cast that into int data type. So for variable in case below this works fine if I want to display it in Standard 112 (ISO)

DECLARE @LoopDate datetime
SET @LoopDate = '12/23/2015'
SELECT @LoopDate AS Original, 
CAST(CONVERT(VARCHAR(8), @LoopDate, 112) AS int) AS int;

But when I put 104 which suppose to gives me error:

Conversion failed when converting the varchar value '23.10.2015' to data type int.

It looks like conversion is actually working but casting into int is not.