Two-digit date format in SQL
For the date part to get the format you want, try this:
SELECT
RIGHT(REPLICATE('0', 2) + CAST(DATEPART(DD, accid) AS VARCHAR(2)), 2) +
RIGHT(REPLICATE('0', 2) + CAST(DATEPART(MM, accid) AS VARCHAR(2)), 2) +
RIGHT(DATEPART(YY, accid), 2) AS CustomFormat
FROM yourtablename
...
DATEPART(DD, accid)
will give you a part of the day and the same for mm
and yy
will give you month and year. Then I added functions RIGHT(REPLICATE('0', 2) + CAST(... AS VARCHAR(2)), 2)
to add a leading zero instead of 1
it will be 01
.
As @ bernd-linde suggested , you can use this function to combine it with a part of the name, for example:
concat(Name, ....) AS ...
Also you can simply SELECT
or UPDATE
whichever you are looking for.
As in the @ bernd-linde fiddle .
source to share