Wednesday, March 7, 2012

date format

how to convert date filed in this format : dd-mmm-yyyy
eg: 28-Mar-2006Try this
declare @.dt varchar(30)
set @.dt ='28-03-2006'
select convert(varchar(30),convert(datetime,y+m
+d,113),100)
from
(
select substring(@.dt ,1,2) as d,
substring(@.dt ,4,2)as m,
substring(@.dt ,7,4)as y
) as der
"Vikram" <aa@.aa> wrote in message
news:%23SGuHJmUGHA.1204@.TK2MSFTNGP12.phx.gbl...
> how to convert date filed in this format : dd-mmm-yyyy
> eg: 28-Mar-2006
>|||Try,
select replace(convert(varchar(11), getdate(), 106), ' ', '-')
go
See function "convert" in BOL.
AMB
"Vikram" wrote:

> how to convert date filed in this format : dd-mmm-yyyy
> eg: 28-Mar-2006
>
>|||Hi Alejandro
Yes, but the OP said that he has dd-mm-yyyy format
select convert(varchar(11),convert(varchar(11),
getdate(), 105),106)
create table #test
(
dt datetime,
t varchar(11)
)
insert into #test (dt) select '28-03-2006'
--failed
insert into #test (t) select '28-03-2006'
select convert(varchar(11),t,106)
from #test
drop table #test
"Alejandro Mesa" <AlejandroMesa@.discussions.microsoft.com> wrote in message
news:28ECC1D7-21F7-45A7-8945-11C736074FB0@.microsoft.com...
> Try,
> select replace(convert(varchar(11), getdate(), 106), ' ', '-')
> go
> See function "convert" in BOL.
> AMB
> "Vikram" wrote:
>|||Where do you want to show the data?
Use Front end application to format the dates
Madhivanan

No comments:

Post a Comment