Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 DAtetime format

Author  Topic 

Kimi86
Yak Posting Veteran

79 Posts

Posted - 2012-08-02 : 07:15:07
Hi all,
I need to create a table with one coulumn as datetime in the format
'YYYY-MM-DD'

Create TAble My_table(
My_Date DATETIME)

This does not give me my required format
please suggest

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2012-08-02 : 07:37:01
SQL Server does not store the dates in a literal format. It has its own internal method of storing datetime efficiently and accurately. What you can do is to format it to your liking when you query the table. For example, to get yyyy-mm-dd format, you would do this:
SELECT
CONVERT(CHAR(10),My_Date,120)
FROM My_Table;
That 120 is a format style - all the styles are described here: http://msdn.microsoft.com/en-us/library/ms187928.aspx

Ideally, experts recommend that you don't even format the dates in your queries. What they recommend is that you send the data as a datetime object to your client program and have it format to whatever format it needs.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-08-02 : 10:00:08
quote:
Originally posted by Kimi86

Hi all,
I need to create a table with one coulumn as datetime in the format
'YYYY-MM-DD'

Create TAble My_table(
My_Date DATETIME)

This does not give me my required format
please suggest




see
http://visakhm.blogspot.com/search/label/date%20addition%20using%20integer%20values

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -