Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Syntax for shortening Datetime

Posted on 2008-10-21
3
Medium Priority
?
268 Views
Last Modified: 2012-05-05
I have a Column in a table that stores the date.  The formating on it is datetime.  I pull from this column for a description that I put in another table.  The description includes other thing in the string so I store it as varchar.  Problem is when I cast the datetime as varchar to store it has the date 10/21/2008 12:00AM.  I don't need the time on there but not sure how to get rid of it since I'm casting it as a varchar.
0
Comment
Question by:Nathan Riley
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 25

Accepted Solution

by:
SStory earned 700 total points
ID: 22770547
convert(varchar,ColName,101)

This should do it...convert a DateTime field named ColName to a varchar using style 101
See this table:
http://msdn.microsoft.com/en-us/library/ms187928.aspx
0
 
LVL 27

Assisted Solution

by:MikeToole
MikeToole earned 700 total points
ID: 22770555
What you need is the TSQL Convert() function which takes a third parameter for dates to specify the style of the date. E.g. for US dates:
select convert(varchar(10), getdate(),101)
Gives:
10/21/2008
 
0
 
LVL 9

Assisted Solution

by:jamesgu
jamesgu earned 600 total points
ID: 22770874
since you've had the string, do this

select cast( cast('10/21/2008 12:00AM' as varchar(10)) as datetime)

0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
When trying to connect from SSMS v17.x to a SQL Server Integration Services 2016 instance or previous version, you get the error “Connecting to the Integration Services service on the computer failed with the following error: 'The specified service …
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

715 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