GeekInterview.com
   Home |  Tech FAQ  |   Interview Questions |  Placement Papers |  Tech Articles |  Learn |  Freelance Projects |  Online Testing |  Geeks Talk |  Job Postings |  Knowledge Base | Site Search |  Add/Ask Question

  GeekInterview.com  >  Interview Questions  >  Database  >  SQL Server

 Print  |  
Question:  What is the code to create a table having a column named DATE, which takes date in the format dd/mm/yyyy, in SQL Server2000? Or any format of date.



June 06, 2006 02:07:10 #3
 Yogesh Srivastava   Member Since: Visitor    Total Comments: N/A 

RE: What is the code to create a table having a column...
 

Hi

Your can try this

SELECT  CONVERT(varchar, GETDATE(), 103)

In this example the GETDATE() will return your sql server system date.

and  the CONVERT is used to convert the date into the desired fomat.

Basically the CONVERT requires three arguments

1. Datatype

2. Date to Convert

3. Format style

Here is the list of style .....

Style ID

Style Type

0 or 100 mon dd yyyy hh:miAM (or PM)
101mm/dd/yy
102yy.mm.dd
103dd/mm/yy
104dd.mm.yy
105dd-mm-yy
106dd mon yy
107Mon dd, yy
108hh:mm:ss
9 or 109 mon dd yyyy hh:mi:ss:mmmAM (or PM)
110mm-dd-yy
111yy/mm/dd
112yymmdd
13 or 113 dd mon yyyy hh:mm:ss:mmm(24h)
114hh:mi:ss:mmm(24h)
20 or 120 yyyy-mm-dd hh:mi:ss(24h)
21 or 121 yyyy-mm-dd hh:mi:ss.mmm(24h)
126yyyy-mm-dd Thh:mm:ss.mmm(no spaces)
130dd mon yyyy hh:mi:ss:mmmAM
131dd/mm/yy hh:mi:ss:mmmAM

Enjoy the Code...

Hope this will help u

     

 

Back To Question