December 5, 2005 at 10:36 am
I am using DatePart to strip the pieces out of a date field to create mm/dd/yyyy format. This is simple, however, it will only do m/d/yyyy format.
Any ideas how to force to mm/dd/yyyy even if it is a single digit day or month? I can do this with a long CASE clause, but I know there has got to be a better way.
Thank you!
December 5, 2005 at 10:59 am
is this what you want ?!
"select convert(varchar, dateField, 101) as formattedDate from myTable"
**ASCII stupid question, get a stupid ANSI !!!**
December 5, 2005 at 11:04 am
YES, exactly! Thank you!
December 5, 2005 at 1:42 pm
Just in case you want a general soulution to the padding problem you can try this if you ever have a need.
declare @month as varchar(10)
set @month = datepart(month, '01/01/2005')
select right('0' + @month,2)
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply