Thursday 7 December 2017

get the time format in sql server query with table column datetime

///////////// query

1.
select CONVERT(varchar(5), [ColumnName],8)+' '+ RIGHT(convert(varchar, [ColumnName], 100), 2) from tableName

// result
12:52 PM

2.
select convert(varchar, getdate(), 108)+ ' ' + RIGHT(convert(varchar, getdate(), 100), 2) as Time

// result
16:23:01 PM

3.
SELECT Convert( VarChar( 10 ), CAST(getdate() AS TIME(0)), 100 )

// result
4:23PM

4.
SELECT ltrim(right(convert(varchar(20), getdate(),108), 7))+' '+ RIGHT(convert(varchar, getdate(), 100), 2)

// result
6:25:04 PM


No comments:

Post a Comment

Excel Sort values in ascending order using function TEXTJOIN

 Excel ::  Text ::  1,3,5,2,9,5,11 Result :: 1,2,3,5,5,9,11 Formula ::     TEXTJOIN ( ",",1,SORT(MID(SUBSTITUTE( A1 ,","...