Solved

SQL Getting date part of a DateTime field error

Posted on 2014-10-17
3
177 Views
Last Modified: 2014-10-18
Hi
I am getting the following error in trying to run the SQL statement below. The column in a client's database
is a DateTime field
'DATE' is not a recognized built-in function name.

Select Phone, [First Name], [Machine operator],[Drilled To]-[Drilled From] As [Drilled m], DATE([Date]) as TheDate From Performance Inner Join People On [Machine operator] = [Operator COY] Where [Drilled To]-[Drilled From] > 10
0
Comment
Question by:murbro
3 Comments
 
LVL 35

Accepted Solution

by:
Robert Schutt earned 250 total points
Comment Utility
you can use CAST:
CAST([Date] as DATE) as TheDate

Open in new window

0
 
LVL 48

Assisted Solution

by:PortletPaul
PortletPaul earned 250 total points
Comment Utility
Depending on your SQL Server version you can output just the date without the time portion using CONVERT() or FORMAT()

SQL Server 2012 on:

FORMAT([date],'yyyy-mm-dd')

with the format() function you can alter the output to 'mm-dd-yyyy' or whatever you prefer


Without the format() function use CONVERT(varchar(length),[Date_field],style_number)

e.g.
CONVERT(varchar(10),[Date_field],120)

Here you need to know what the style numbers refer to, refer to a list of those is here. Note that in the above example the output is truncated at 10 characters hence you will not see any time portion.

If you use CAST([date_field] as date) then the default display format is applied, which might be, or might not be, the desired outcome
0
 

Author Closing Comment

by:murbro
Comment Utility
Thanks
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Introduced in Microsoft SQL Server 2005, the Copy Database Wizard (http://msdn.microsoft.com/en-us/library/ms188664.aspx) is useful in copying databases and associated objects between SQL instances; therefore, it is a good migration and upgrade tool…
Let's review the features of new SQL Server 2012 (Denali CTP3). It listed as below: PERCENT_RANK(): PERCENT_RANK() function will returns the percentage value of rank of the values among its group. PERCENT_RANK() function value always in be…
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Via a live example, show how to shrink a transaction log file down to a reasonable size.

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now