Answered by:
How to convert a datetime field to a date field in SQL

Question
-
Hi,
I embedded a SQL query in excel that gets some datetime fields like "TASK_FINISH_DATE" .
How can I convert a datetime field to a date field in SQL in a way that excel will recognize it as a date type and not a text type?
I tried:
CONVERT(varchar(8),TASK_FINISH_DATE ,3)
CONVERT(Date,TASK_FINISH_DATE ,3)
CAST(TASK_FINISH_DATE as date)
**all of the above returned text objectes in excel and not date objects.
Thanks!
Sunday, May 17, 2015 1:14 PM
Answers
-
Thanks for the response! The problem is that even if I format the column as a date, every
object itself still contains the hour. I wish to delete the hour completely...<o:p></o:p>Any ideas?<o:p></o:p>
you should be able to eliminate that hour part in the query, if you do not want.. how is your date stored in sql server?
refer this on how to do it http://www.sql-server-helper.com/tips/date-formats.aspx
Hope it Helps!!
- Marked as answer by Lydia ZhangMicrosoft contingent staff Monday, May 25, 2015 8:19 AM
Thursday, May 21, 2015 12:20 PMAnswerer
All replies
-
typically, whenever I have to import dates into excel, I first format column in excel as date data type.
right click on the column in excel and you should see an option to format...
I cannot recall if it is date or datetime....
if not, you can custom format the column the
Hope it Helps!!
- Proposed as answer by Lydia ZhangMicrosoft contingent staff Monday, May 18, 2015 5:27 AM
Sunday, May 17, 2015 2:22 PMAnswerer -
Thanks for the response! The problem is that even if I format the column as a date, every
object itself still contains the hour. I wish to delete the hour completely...<o:p></o:p>Any ideas?<o:p></o:p>
Thursday, May 21, 2015 11:56 AM -
Thanks for the response! The problem is that even if I format the column as a date, every
object itself still contains the hour. I wish to delete the hour completely...<o:p></o:p>Any ideas?<o:p></o:p>
you should be able to eliminate that hour part in the query, if you do not want.. how is your date stored in sql server?
refer this on how to do it http://www.sql-server-helper.com/tips/date-formats.aspx
Hope it Helps!!
- Marked as answer by Lydia ZhangMicrosoft contingent staff Monday, May 25, 2015 8:19 AM
Thursday, May 21, 2015 12:20 PMAnswerer