SQL Longdate to Shortdate conversion syntax

IntercareSupport
IntercareSupport used Ask the Experts™
on
Hello,

I'm trying to convert a date out of a sql server 2005 database in this format:
1900-01-01 00:00:00.000

to a shorter date length.  I'm having some unexpected trouble doing this.  Any thoughts?  Thanks.
select
date_in_table
from
important_table

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Database Consultant
Top Expert 2009
Commented:
select CONVERT(varchar(10), date_in_table, 120) as date_in_Table
from
important_table
Kevin CrossChief Technology Officer
Most Valuable Expert 2011
Commented:
IntercareSupport,

You can use the CONVERT function within MS SQL.

http://msdn.microsoft.com/en-us/library/ms187928.aspx

See the code snippet below for an example.

Best regards,
isa
select
convert(varchar, date_in_table, 120)
-- or alternatively, use a size to shorten even further
-- e.g, this should stop at minutes yyyy-mm-dd hh:mi
, convert(varchar(16), date_in_table, 120)
from
important_table

Open in new window

Author

Commented:
Thanks!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial