Skip to main content
added 92 characters in body
Source Link
Dale K
  • 28.1k
  • 15
  • 59
  • 85

A datetime doesn't have that level of precision, instead use datetime2:

select cast('2020-10-10 07:30:00.0000000' as datetime2); 

And to only show the desired string, cast it to a shorter string:

select cast(cast('2020-10-10 07:30:00.0000000' as datetime2) as varchar(19)); 

Obviously it makes no sense to cast a string to date and back again, but I assume you have simplified youractualyour actual use-case. Otherwise you could use:

select cast('2020-10-10 07:30:00.0000000' as varchar(19)); 

A datetime doesn't have that level of precision, instead use datetime2:

select cast('2020-10-10 07:30:00.0000000' as datetime2); 

And to only show the desired string, cast it to a shorter string:

select cast(cast('2020-10-10 07:30:00.0000000' as datetime2) as varchar(19)); 

Obviously it makes no sense to cast a string to date and back again, but I assume you have simplified youractual use-case.

A datetime doesn't have that level of precision, instead use datetime2:

select cast('2020-10-10 07:30:00.0000000' as datetime2); 

And to only show the desired string, cast it to a shorter string:

select cast(cast('2020-10-10 07:30:00.0000000' as datetime2) as varchar(19)); 

Obviously it makes no sense to cast a string to date and back again, but I assume you have simplified your actual use-case. Otherwise you could use:

select cast('2020-10-10 07:30:00.0000000' as varchar(19)); 
added 154 characters in body
Source Link
Dale K
  • 28.1k
  • 15
  • 59
  • 85

A datetime doesn't have that level of precision, instead use datetime2:

select cast('2020-10-10 07:30:00.0000000' as datetime2); 

And to only show the desired string, cast it to a shorter string:

select cast(cast('2020-10-10 07:30:00.0000000' as datetime2) as varchar(19)); 

Obviously it makes no sense to cast a string to date and back again, but I assume you have simplified youractual use-case.

A datetime doesn't have that level of precision, instead use datetime2:

select cast('2020-10-10 07:30:00.0000000' as datetime2); 

A datetime doesn't have that level of precision, instead use datetime2:

select cast('2020-10-10 07:30:00.0000000' as datetime2); 

And to only show the desired string, cast it to a shorter string:

select cast(cast('2020-10-10 07:30:00.0000000' as datetime2) as varchar(19)); 

Obviously it makes no sense to cast a string to date and back again, but I assume you have simplified youractual use-case.

Source Link
Dale K
  • 28.1k
  • 15
  • 59
  • 85

A datetime doesn't have that level of precision, instead use datetime2:

select cast('2020-10-10 07:30:00.0000000' as datetime2);