Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

This seems like something trivial would be easy, but I couldn't find a good way to do it.

This is what I came up with:

select convert(numeric,
                    (select convert(varchar,datepart(yy,getdate())) + 
                         right('0' + convert(varchar,datepart(mm,getdate())), 2) +
                         right('0' + convert(varchar,datepart(dd,getdate())), 2)
                    ))

EDIT: I know it doesn't need to have a subquery like that, but ignore that =p

share|improve this question
add comment

1 Answer

up vote 3 down vote accepted

Much simpler: CONVERT(varchar(8),GETDATE(),112)

You can find a full list of CONVERT styles in Sybase BOL, although the explanation of each style isn't particularly clear (and is actually flat wrong for style 12 & 112). The Complete Sybase ASE Reference Guide includes a full list of styles with examples. (Please note that the complete guide is externally published, not from Sybase. Also I'm not affiliated with the book or the publisher, just mentioning it because everyone working with ASE should have a copy of it.)

share|improve this answer
    
Yes, it does seem to be wrong for 112. I had already seen this, but assumed it wouldn't work for me. –  user606723 May 18 '12 at 14:15
    
If you know that the size won't change you should use char ;) convert(char(8), getdate(), 112) –  aF. Nov 5 '13 at 15:52
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.