Reputation: 83
select replace(substring(CONVERT(varchar,SWITCHOFFSET(SYSDATETIMEOFFSET(), '+05:30'),100),13,
LEN(CONVERT(varchar,SYSDATETIMEOFFSET(),100))), ' +05:30','')
I am getting output=> 4:06PM
but I want output=> 4:06 PM
how can I get this output??
Upvotes: 0
Views: 50
Reputation: 362
Below query will give you the expected output.
SELECT replace(substring(STUFF(CONVERT(varchar,SWITCHOFFSET(SYSDATETIMEOFFSET(), '+05:30'),100), 18, 0, ' '),13,LEN(CONVERT(varchar,SYSDATETIMEOFFSET(),100))), ' +05:30','');
output: 4:22 PM
Upvotes: 0
Reputation: 21
select replace(substring(CONVERT(varchar,SWITCHOFFSET(SYSDATETIMEOFFSET(), '+05:30 '),100),13,
LEN(CONVERT(varchar,SYSDATETIMEOFFSET(),100))),' +05:30',' ')
Upvotes: 1
Reputation: 300
Use this SELECT replace(substring(STUFF(CONVERT(varchar,SWITCHOFFSET(SYSDATETIMEOFFSET(), '+05:30'),100), 18,0,' '),13,LEN(CONVERT(varchar,SYSDATETIMEOFFSET(),100))), ' +05:30','');
instead of
select replace(substring(CONVERT(varchar,SWITCHOFFSET(SYSDATETIMEOFFSET(), '+05:30 '),100),13,
LEN(CONVERT(varchar,SYSDATETIMEOFFSET(),100))),' +05:30',' ')
Upvotes: 1
Reputation: 878
You can use stuff
select STUFF(replace(substring(CONVERT(varchar(50),SWITCHOFFSET(SYSDATETIMEOFFSET(), '+05:30'),100),13, LEN(CONVERT(varchar,SYSDATETIMEOFFSET(),100))), ' +05:30',''),6,0,' ')
It will stuff a space at the 6th position replacing 0 characters.
Upvotes: 0