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 2005 Forums
 Transact-SQL (2005)
 Split Month and Year in DateTime Field

Author  Topic 

itnagaraj
Yak Posting Veteran

70 Posts

Posted - 2010-09-17 : 08:46:35
I want Month and Year in Datetime field.
Result
------
1. 09-2010

2. 092010

V.NAGARAJAN

sakets_2000
Master Smack Fu Yak Hacker

1472 Posts

Posted - 2010-09-17 : 08:48:10
why would you want to do this?
Go to Top of Page

itnagaraj
Yak Posting Veteran

70 Posts

Posted - 2010-09-17 : 08:49:26
Cutomer Needs this

quote:
Originally posted by sakets_2000

why would you want to do this?



V.NAGARAJAN
Go to Top of Page

sakets_2000
Master Smack Fu Yak Hacker

1472 Posts

Posted - 2010-09-17 : 08:55:38
your select to display that format can be
select convert(month(column),varchar(2))+convert(year(column),varchar(4)) from table



Go to Top of Page

sakets_2000
Master Smack Fu Yak Hacker

1472 Posts

Posted - 2010-09-17 : 08:57:28
You'd need to add in a case statement to above if you want leading zeroes to month part.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-09-17 : 12:18:54
quote:
Originally posted by itnagaraj

Cutomer Needs this

quote:
Originally posted by sakets_2000

why would you want to do this?



V.NAGARAJAN


is it for display purposes?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -