All of Query was successfully tested and running well on Microsoft SQL Server 2008

Rabu, 29 Agustus 2012

sql date convert

SQL Server Convert Date Time Function Statement:
Convert(data_type(length),expression,style)

declare @CurrDate datetime
set @CurrDate='2012-08-30 07:54:52.293'

select (100)ShowStyle,Convert(nvarchar,@CurrDate,100)ShowOutput Union
select (101),Convert(nvarchar,@CurrDate,101) Union
select (102),Convert(nvarchar,@CurrDate,102) Union
select (103),Convert(nvarchar,@CurrDate,103) Union
select (104),Convert(nvarchar,@CurrDate,104) Union
select (105),Convert(nvarchar,@CurrDate,105) Union
select (106),Convert(nvarchar,@CurrDate,106) Union
select (107),Convert(nvarchar,@CurrDate,107) Union
select (108),Convert(nvarchar,@CurrDate,108) Union
select (109),Convert(nvarchar,@CurrDate,109) Union
select (110),Convert(nvarchar,@CurrDate,110) Union
select (111),Convert(nvarchar,@CurrDate,111) Union
select (112),Convert(nvarchar,@CurrDate,112) Union
select (113),Convert(nvarchar,@CurrDate,113) Union
select (114),Convert(nvarchar,@CurrDate,114) Union
select (120),Convert(nvarchar,@CurrDate,120) Union
select (121),Convert(nvarchar,@CurrDate,121) Union
select (126),Convert(nvarchar,@CurrDate,126) Union
select (130),Convert(nvarchar,@CurrDate,130) Union
select (131),Convert(nvarchar,@CurrDate,131)

#Results:
ShowStyle    ShowOutput
100          Aug 30 2012  7:54AM
101          08/30/2012
102          2012.08.30
103          30/08/2012
104          30.08.2012
105          30-08-2012
106          30 Aug 2012
107          Aug 30, 2012
108          07:54:52
109          Aug 30 2012  7:54:52:293AM
110          08-30-2012
111          2012/08/30
112          20120830
113          30 Aug 2012 07:54:52:293
114          07:54:52:293
120          2012-08-30 07:54:52
121          2012-08-30 07:54:52.293
126          2012-08-30T07:54:52.293
130          13 شوال 1433  7:54:52:293AM
131          13/10/1433  7:54:52:293AM

Tidak ada komentar:

Posting Komentar