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.
| Author |
Topic |
|
vasu4us
Posting Yak Master
102 Posts |
Posted - 2007-06-28 : 14:11:22
|
| how do i get dates as 200706i 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 |
 |
|
|
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 200706can you check once againthanks |
 |
|
|
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/ |
 |
|
|
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) |
 |
|
|
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] |
 |
|
|
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") MadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|
|
|