Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Specific Date format help!

Author  Topic 

Gopher
Yak Posting Veteran

83 Posts

Posted - 2006-05-05 : 04:00:50
Hi All

This is possibly a simple problem to solve but I am fing it a little difficult.

I am trying to create an T-SQL query that returns the current year and month e.g. '200604'. I have been looking at the datepart function and so far I can get

datepart(yyyy,GetDate()) which returns 2006
datepart(mm,GetDate()) which returns 4 (i need '04')

I need them combined to produce '200604' any ideas?

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-05-05 : 04:02:38
select convert(varchar(6), getdate(), 112)


KH

Go to Top of Page

Gopher
Yak Posting Veteran

83 Posts

Posted - 2006-05-05 : 04:04:08
Awsome!

Thanks khtan
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-05-05 : 04:07:19
also refer to http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=55210&SearchTerms=Date%20formatting,Format%20Date


KH

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-05-05 : 04:15:44
Also, use front end application to format the date

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -