tsql - Two Digit date format in SQL -
i have table field accid
have concatenate name
date
'myname-010415' in sql query.
date format 01-04-2015
or 01/04/2015
. want display 010415
.
for date part, format want you, try this:
select right(replicate('0', 2) + cast(datepart(dd, accid) varchar(2)), 2) + right(replicate('0', 2) + cast(datepart(mm, accid) varchar(2)), 2) + right(datepart(yy, accid), 2) customformat yourtablename ...
the datepart(dd, accid)
give day part , same mm
, yy
give month , year parts. added functions right(replicate('0', 2) + cast(... varchar(2)), 2)
add leading zero, instead of 1
01
.
as @bernd-linde suggested, can use function concatenate name part like:
concat(name, ....) ...
also can select
or update
depending on looking for.
as in @bernd-linde's fiddle.
Comments
Post a Comment