Solved

How can I convert this to date only

Posted on 2009-07-14
6
204 Views
Last Modified: 2012-05-07
SELECT * FROM (SELECT  Distinct c.CustomerID,  e.Name, o.OrderID, o.CreatedOn, oi.Quantity,

I would like to convert or format this date,time to date only.

38      Oregon      1      2009-06-27 08:51:43.960      1      Oregon      0.264      0.000      0.176880      0.000000      0.67            .77             14      Name: Dennis West City: Eagle Point
0
Comment
Question by:westdh
6 Comments
 
LVL 75

Accepted Solution

by:
Aneesh Retnakaran earned 500 total points
ID: 24854924

SELECT CONVERT(varchar(10), o.CreatedOn, 120 ) CreatedOn
0
 
LVL 75

Expert Comment

by:Aneesh Retnakaran
ID: 24854926
SELECT * FROM (SELECT  Distinct c.CustomerID,  e.Name, o.OrderID, CONVERT(varchar(10), o.CreatedOn, 120 ) CreatedOn , oi.Quantity ) a
0
 
LVL 59

Expert Comment

by:Kevin Cross
ID: 24855002
Just note that using convert you are changing the date to a string; therefore, if you still want to treat this value as a date you may want to consider what your need for removing time is.  If you need that just to have records created different times throughout a day to group together, then you can also use date functions like this to make the dates all as of midnight of date.

SELECT *
FROM (SELECT  Distinct c.CustomerID,  e.Name, o.OrderID, DATEADD(d, 0, DATEDIFF(d, 0, o.CreatedOn)) CreatedOn , oi.Quantity ) a
0
 
LVL 26

Expert Comment

by:Chris Luttrell
ID: 24855544
I agree with mwvisa1.
Also, why are you doing
Select * from (Select Distinct ...
This query raises red flags to me, maybe you should describe what you are doing and someone here can offer some good SQL practices advice.
0
 

Author Closing Comment

by:westdh
ID: 31603531
Solve it..Thanks
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

809 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