November 29, 2006 at 6:56 am
I have a date field in varchar format in the table. It's in 2/2/2002 format but I want it in 02/02/2002 format. How can I do this?
I used convert(datetime,a.datehired,100) and other combinations but nothing works. Is it possible at all?
Thanks,
Kiran
November 29, 2006 at 4:23 pm
select
right('0' + cast(datepart(month,a.datehired) as char(2)), 2)
+ '/'
+ right('0' + cast(datepart(day,a.datehired) as char(2)), 2)
+ '/'
+ cast(datepart(year,a.datehired) as char(4))
______________________________________________________________________
Personal Motto: Why push the envelope when you can just open it?
If you follow the direction given HERE[/url] you'll likely increase the number and quality of responses you get to your question.
Jason L. SelburgNovember 29, 2006 at 9:57 pm
Well, ignoring issues of ambiguity (dd/mm/yyyy or mm/dd/yyyy?)
select convert(varchar(10),convert(datetime, '2/2/2002'),101)
works fine for me.
November 30, 2006 at 6:52 am
Yes, this worked for me. Thanks!
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply