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

How to highlight selected text in notepad++

  –> To highlight a block of code in Notepad++, please do the following steps step-1  :- Select the required text. step-2  :- Right click...