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
 General SQL Server Forums
 New to SQL Server Programming
 date as 20070628

Author  Topic 

vasu4us
Posting Yak Master

102 Posts

Posted - 2007-06-28 : 14:11:22
how do i get dates as 200706

i tried select cast(datepart(yyyy,getdate()) as char(4)) +
cast(datepart(mm,getdate()) as char(2))

but it gives 20076. i need to get 200706 to compare it with other table.
did any one try this.

jezemine
Master Smack Fu Yak Hacker

2886 Posts

Posted - 2007-06-28 : 14:34:25
select cast(datepart(yyyy,getdate()) as char(4)) + right('00' + cast(datepart(mm,getdate()) as varchar char(2)), 2)

thanks for correcting me dinakar.

i shouldn't be so quick to copy/paste!


elsasoft.org
Go to Top of Page

vasu4us
Posting Yak Master

102 Posts

Posted - 2007-06-28 : 14:55:43
thank you jezemine, but it just gives me mont as a single digit for june i wanted it to be 06.the total output to be 200706
can you check once again
thanks
Go to Top of Page

dinakar
Master Smack Fu Yak Hacker

2507 Posts

Posted - 2007-06-28 : 15:01:29
[code] select right('00' + convert(varchar,(month(getdate()))),2) [/code]

Dinakar Nethi
************************
Life is short. Enjoy it.
************************
http://weblogs.sqlteam.com/dinakar/
Go to Top of Page

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2007-06-28 : 15:17:58
Here is another way:
SELECT CONVERT(VARCHAR(6), GETDATE(), 112)
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-06-28 : 19:59:04
How about doing it in front end ?


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-06-28 : 23:56:40
quote:
Originally posted by khtan

How about doing it in front end ?


KH
[spoiler]Time is always against us[/spoiler]



Format(Rs("datecol"),"YYYYMM")

Madhivanan

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

- Advertisement -