Solved

Syntax for shortening Datetime

Posted on 2008-10-21
3
254 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:N R
3 Comments
 
LVL 25

Accepted Solution

by:
SStory earned 175 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 175 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 150 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

If you find yourself in this situation “I have used SELECT DISTINCT but I’m getting duplicates” then I'm sorry to say you are using the wrong SQL technique as it only does one thing which is: produces whole rows that are unique. If the results you a…
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
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.

758 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

19 Experts available now in Live!

Get 1:1 Help Now