Convertion from dd/mm/yyyy to mm-yyyy in server server [Resolved]

Posted by Naseer under Sql Server on 2/26/2014 | Points: 10 | Views : 1669 | Status : [Member] | Replies : 4
Hi friends,

i need to convert dd/mm/yyyy to mm-yyyy in server server


ex:01-10-2014 00:00:00 to oct-2014 kindly help me.




Responses

Posted by: kgovindarao523-21772 on: 2/27/2014 [Member] [MVP] Bronze | Points: 50

Up
0
Down

Resolved
Hi,
Please try this code

with testdata as
(
select cast('01-10-2014 00:00:00' as datetime) as d
)
SELECT DATENAME(MONTH,d)+'-'+DATENAME(year,d)


Thank you,
Govind

Naseer, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Murugavelmsc on: 2/27/2014 [Member] Starter | Points: 25

Up
0
Down
DECLARE @InputDate AS varchar(100)
SET @InputDate = (select cast('10/01/2014 12:00:00 AM' as datetime))
select substring(convert(char(20), @InputDate, 100), 1, 3)+ '-' + convert(char(4), year(@InputDate))

Regards,
Murugavel S
murugavel.sadagopan@gmail.com
http://murugavelmsc.blogspot.in/

Naseer, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Bandi on: 2/27/2014 [Member] [MVP] Platinum | Points: 25

Up
0
Down
Check


DECLARE @InputDate VARCHAR(25) = '10/1/2014' --convert dd/mm/yyyy to mm-yyyy
SELECT RIGHT(CONVERT(VARCHAR(10), CAST( @InputDate AS DATETIME), 105), 7) AS [MM-YYYY]


Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

Naseer, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Bandi on: 3/2/2014 [Member] [MVP] Platinum | Points: 25

Up
0
Down
Mark This Response as Answer link if the above solution helped you

Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

Naseer, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response