Ganesh bagad
Ganesh bagad

Reputation: 83

How to get space between following output

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

Answers (4)

Chintan Udeshi
Chintan Udeshi

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

Ruchika_C
Ruchika_C

Reputation: 21

select replace(substring(CONVERT(varchar,SWITCHOFFSET(SYSDATETIMEOFFSET(), '+05:30 '),100),13,
LEN(CONVERT(varchar,SYSDATETIMEOFFSET(),100))),' +05:30',' ')

Upvotes: 1

Tushar_G
Tushar_G

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

rexroxm
rexroxm

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

Related Questions