satya
satya

Reputation: 373

Sql remove milliseconds and Date Conversion

Please could any one suggest me getting the right results?

I have a Date field which results in "2016-07-08 10:09:22.910" format and wish to remove milliseconds and same time wish to convert this field in to "08/07/2016 10:09:22"

I managed to remove the milliseconds by using CONVERT(VARCHAR, [DateFileCreated], 20) but unable to convert this in to the desired format.

Please suggest

Upvotes: 0

Views: 4276

Answers (2)

TheGameiswar
TheGameiswar

Reputation: 28890

In SQL Server ,you can use FORMAT available from SQL Server 2012

SELECT FORMAT ( getdate(), 'yyyy-MM-dd HH:mm:ss' ) 

Output:

2016-07-11 07:13:33

Upvotes: 3

Gordon Linoff
Gordon Linoff

Reputation: 1269633

The reference to convert() suggests that you are using SQL Server. You can see the list of formats supported by convert() in the documentation.

Format 131 is very close to what you want:

select convert(varchar(255), DateFileCreated, 131)

In SQL Server 2012+, you can use format() to get exactly what you want. The documentation for this function is here.

Upvotes: 1

Related Questions