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 |
hollyquinn
Starting Member
31 Posts |
Posted - 2009-02-18 : 15:28:58
|
Hi I am trying to format a datetime column to the format MM/YYYY. I have figured out how to format it as MM/DD/YYYY, but not as just month and year. This is what I've got:select SessionMonth = CONVERT(char(10), SessionMonth, 101) from tblSessionIDCan anyone help me? Thanks. |
|
sakets_2000
Master Smack Fu Yak Hacker
1472 Posts |
Posted - 2009-02-18 : 15:30:43
|
datepart or datename function might help you.select convert(varchar,datepart(mm,getdate()))+'/'+convert(varchar,datepart(year,getdate()))select datename(mm,getdate())+'/'+datename(year,getdate()) |
|
|
sakets_2000
Master Smack Fu Yak Hacker
1472 Posts |
Posted - 2009-02-18 : 15:40:28
|
Also, There is no MM/YYYY type date format, you'll have to convert it to varchar for this. |
|
|
Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)
7020 Posts |
Posted - 2009-02-18 : 15:57:31
|
[code]select [MM/YYYY] = right(convert(varchar(10),getdate(),103),7)Results:MM/YYYY ------- 02/2009(1 row(s) affected)[/code]CODO ERGO SUM |
|
|
hollyquinn
Starting Member
31 Posts |
Posted - 2009-02-18 : 16:12:04
|
quote: Originally posted by Michael Valentine Jones
select [MM/YYYY] = right(convert(varchar(10),getdate(),103),7)Results:MM/YYYY ------- 02/2009(1 row(s) affected) CODO ERGO SUM
Hi Michael, how do you do what you are doing above on a Column instead of just the current date? Thanks. |
|
|
hollyquinn
Starting Member
31 Posts |
Posted - 2009-02-18 : 16:13:32
|
quote: Originally posted by Michael Valentine Jones
select [MM/YYYY] = right(convert(varchar(10),getdate(),103),7)Results:MM/YYYY ------- 02/2009(1 row(s) affected) CODO ERGO SUM
Oh nevermind! I got it! Replace MM/YYYY with my column name. Thanks so much. :) |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
|
|
|
|