Solved

Syntax for shortening Datetime

Posted on 2008-10-21
3
255 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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

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…
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

895 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

11 Experts available now in Live!

Get 1:1 Help Now