question

Murali avatar image
Murali asked

how to get only mmyyyy format

i need to get date like '092010' .... to get the above format ..i am doing .... month(getdate())+year(getdate()) ...but i am getting '92010'...instead of '092010'...
t-sql
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
Kev Riley avatar image
Kev Riley answered
here's one way.... convert the date to a varchar using style 103 (dd/mm/yyyy), then replace the '/' with '', and take the rightmost 6 chars select right(replace(convert(varchar, getdate(), 103),'/',''),6) which gives (whilst the date is in Sept 2010) 092010 There are literally hundreds of different ways of doing this by using the date conversion styles
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.