Ways of getting different different time formats

vishalneeraj-24503
Posted by vishalneeraj-24503 under Sql Server category on | Points: 40 | Views : 796
select convert(varchar(8), getdate(), 108) as time_only;

Output:
18:25:18

select convert(varchar(5),getdate(),108) time_only;

Output:
18:47

select substring(convert(varchar, getdate(), 114),1,5) time_only;

Output:
18:47

select convert(char(5), getdate(),108) time_only;

Output:
18:47

select convert(varchar, getdate(), 114) as [hh:mi(24h)]

Output:
18:41:38:093

select ltrim(right(convert(varchar(20),getdate(),100),7)) '12 hour format';

Output:
6:37pm

select right(convert(char(20),getdate(),0),7) '12 hour format';

Output:
6:51pm

select right(convert(char(20),getdate(),100),7) '12 hour format';

Output:
6:51pm

select convert(nvarchar,cast(getdate()as time),100);

Output:
6:51pm

select convert(time,getdate()) as hour_minute_second;

Output:
18:44:48.8100000

select cast(getdate() as time) as hour_minute_second;

Output:
18:44:48.8100000

Comments or Responses

Login to post response