SQL VarChar to Date -
hi trying convert varchar date field (e.g. 20100320) real date field
'dd/mm/yyyy' (e.g. 20/03/2010).
i have tried 2 ways: a)
(select min(cast(a.dateofaction date)) expr1 resadm.action (a.personid = p.personid)) 'period from',
b)
(select min(convert(date, a.dateofaction, 103)) expr1 resadm.action (a.personid = p.personid)) 'period from',
both producing result
yyyy-mm-dd (e.g. 2010-03-20)
but want result
dd/mm/yyyy (e.g. 20/03/2010)
any appreciated. thanks.
try this:
select convert(varchar(8), convert(datetime, min(a.dateofaction), 112), 103)
your problem once have date format, sql server dump out in default date format, you've discovered yyyy-mm-dd
. need convert date
varchar
format want. convert date, need first convert date! 112 format yyyymmdd
, , 103 format dd/mm/yyyy
, why need these formats. (books online reference date formats)
Comments
Post a Comment