-1

I have to remove time stamp from a datetime datatype in SQL server and want to keep the output data type as date with this format -> mm/dd/yyyy (This outpu should be displayed as date data type not as a string data type ). I am using SQL server 2012.

Please help

Thanks

Drake
  • 97
  • 4
  • 8
  • 1
    You'll have to go into a bit more detail. Do you have a table that you're trying to change the data type of? Are you simply trying to change this in a select statement? – Rich Benner Nov 14 '16 at 15:28
  • Thanks for your time Rich, Its a date column from the date dimension table. since it is a datetime column , i see the timestamp. i dont want to see the timestamp in my output and want to see the date in this format -> mm/dd/yyyy – Drake Nov 14 '16 at 17:49
  • Ok cool, check Gordon's answer. I think that should cover it – Rich Benner Nov 14 '16 at 17:55

2 Answers2

4

In SQL Server, a date is essentially a datetime with no time component. You can do the conversion simply by doing:

cast(datetimecol as date)

Both, though are stored using an internal format. The output format is controlled by internationalization settings (or the database default). You can output either type of column as a string whose format is mm/dd/yyyy by using conversion format 101:

select convert(varchar(10), <col>, 101)

The output is then a string with the format you want.

Nimantha
  • 6,405
  • 6
  • 28
  • 69
Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786
0

Have you tried CONVERT(date, [FieldName]) ?

Please find documentation on this and CAST() here.