简体   繁体   中英

SQL Server 2012 Date Change

I am attempting to convert the DATETIME Column titled CREAT_DTTM to a simple "1/1/2014" format.

I have looked at CAST , CONVERT and FORMAT functions but i just can't get it to work.

Any guidance would be greatly appreciated! I am running SQL Server 2012

Some sample data

CREAT_DTTM
------------------------    
2014-01-01 00:33:58.000    
2014-01-01 00:33:58.000    
2014-01-01 07:40:01.000    
2014-01-01 09:50:27.000    
2014-01-01 10:40:04.000    
2014-01-01 10:40:04.000

By convert I mean: This data is being pulled from another table by a stored proc our developer created. It is sales data that shows when an order has been entered into the system. I created a powerpivot data slicer in Excel that is linked to this table but they do not like the format the date is displayed in. So I was attempting to convert it from the aforementioned format to one more acceptable by the stakeholders. Only thing is that I do not have ample experience in writing queries

You can change the format of the dates in a PowerPivot table through the PowerPivot Window. The advantage here is that you do not need to do any modification of your stored procedure and your datatype is still a date when it comes into your pivot table.

Open your PowerPivot Window again 在此处输入图片说明

Select your data column, Select Fromat from the Formatting section on the Home tab. 在此处输入图片说明

Try the following.

select convert(varchar(10), creat_dttm, 101)
from yourTable

I think that CAST will do the job nicely for you, eg

select cast(creat_dttm as date)
from theTable

尝试这个:

select convert(varchar(15), creat_dttm, 101) from tblTableName

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM