Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need month and day WITH leading zero 2

Status
Not open for further replies.

bigfoot

Programmer
May 4, 1999
1,779
US
When I use Month('07/01/2006') it returns 7
When I use DatePart(mm,'07/01/2006') it returns 7

I'd like 07, and the day 01 because I need to format it on the fly in a query because I'm taking todays date and compairing it against a field that
looks like this -> '#2006\07\06\DOCxyz'

Yes I know the slashes are reversed in the table. It's not my table. :)


(help... please)
 
Month and Datepart return integers, so you would have to convert it to varchar and pad it with a zero.

Select Right('0' + Convert(VarChar(2), Month(GetDate())), 2)

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
WOW! I've been looking at this for more then an hour!

Thanks so much.

My problem was I was not taking the right 2 characters!
I wound up with 3 characters when 10,11, or 12.

Thanks again
 
Code:
SELECT REPLACE(CONVERT(varchar(10),GETDATE(),111),'/','\')+DOCxyz'

Borislav Borissov
VFP9 SP1, SQL Server 2000/2005.
 
Interesting answer bborissov.
I had forgot all about Replace.

Thanks to both of you.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top