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 2008 Forums
 Transact-SQL (2008)
 GetDate in Where Clause

Author  Topic 

Informer30
Starting Member

26 Posts

Posted - 2014-05-07 : 15:34:22
Hi,

I need to get extract the year and month from the currentdate and concatenate with 01

YYYYMM01

e.g. 20140501

I have tried various ways :

left
datepart
cast
convert

But just not happening, please can anyone help...

Thanks

djj55
Constraint Violating Yak Guru

352 Posts

Posted - 2014-05-07 : 15:38:07
What is your code?
SELECT CONVERT(VARCHAR(8), GETDATE(), 112) + '01'

or
SELECT DateAdd(Month, DateDiff(Month, 0, GETDATE), 0)




djj
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2014-06-17 : 03:36:59
You can find more information at the end of this post http://beyondrelational.com/modules/2/blogs/70/posts/10899/understanding-datetime-column-part-iii.aspx

Madhivanan

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

MuralikrishnaVeera
Posting Yak Master

129 Posts

Posted - 2014-06-18 : 01:16:22
Just an edit to dj

SELECT CONVERT(CHAR(6), GETDATE(), 112 )+ '01' AS TheDate -- 20140601

---------------
Murali Krishna

You live only once ..If you do it right once is enough.......
Go to Top of Page
   

- Advertisement -