0

Function to get time stamp to date format for example

Date Field
2014-06-15 00:00:00.000

I want it to show the date as 6/15/2014 in another column call day.

What function do i use in sql server?

Thanks

Nguyenal07
  • 137
  • 2
  • 10

3 Answers3

0
Select Convert(Varchar,Convert(Date,'2014-06-15 00:00:00.000'),110)
Khurram Ali
  • 1,659
  • 4
  • 20
  • 37
0

For SQL 2012 and above:

DECLARE @TimeStamp DATETIME = '2014-06-15 00:00:00.000'

SELECT FORMAT(@TimeStamp,'d','en-US') AS Format_Date

Results:

Format_Date
---------------
6/15/2014
Stephan
  • 5,891
  • 1
  • 16
  • 24
0

If the source column is of type Datetime and target column can be of varchar then you can simply write as:

SELECT CONVERT(VARCHAR(10), mydatetimecolumn, 101) AS [MM/DD/YYYY]
From Testtable

else if source column is of type varchar and you are sure that all dates are valid then you can write as:

SELECT CONVERT(VARCHAR(10), cast('2014-06-15 00:00:00.000' as datetime),
101) AS [MM/DD/YYYY]
Deepshikha
  • 9,896
  • 2
  • 21
  • 21