Tag Info

New answers tagged


You shouldn't care about whether it's 17:00 or 5:00 PM. How SQL Server ends up storing the time is irrelevant (formatting is for the presentation tier) - you should be focusing on converting the data to the right time value and storing it as the right data type (in this case probably datetime, but in modern versions of SQL Server, just time). DECLARE @s ...


You cannot specify a format when converting text to text; you'd need to convert it to a DATE value first. However, in this scenario you don't need to round-trip through DATE. Just: DECLARE @Input CHAR(5) = '0500p' SELECT CAST(CAST(LEFT(@Input, 2) AS TINYINT) + CASE WHEN RIGHT(@Input, 1) = 'p' THEN 12 ELSE 0 END AS VARCHAR(2)) + ':' + ...

Top 50 recent answers are included