You must Sign In to post a response.
  • Category: .NET

    How to convert December-2017 to 201712

    i have date format like December-2017 i want to convert 201712 please helm me to conversion how to do that .
  • #769528
    Hi Chanti,

    I am not sure at where you want this output, I have prepared a logic in SQL. You can convert the same into a function and use it

    DECLARE @InputDate NVARCHAR(50) = 'December-2017'
    DECLARE @Index INT = CHARINDEX('-',@InputDate)
    DECLARE @MonthName NVARCHAR(20)= UPPER(SUBSTRING(@InputDate,0,@Index))
    DECLARE @YearDate NVARCHAR(20) = SUBSTRING(@InputDate,@Index + 1,(LEN(@InputDate) - @Index) + 1)

    SELECT @YearDate+(CASE WHEN @MonthName = 'JANUARY' THEN '01'
    WHEN @MonthName = 'FEBRUARY' THEN '02'
    WHEN @MonthName = 'MARCH' THEN '03'
    WHEN @MonthName = 'APRIL' THEN '04'
    WHEN @MonthName = 'MAY' THEN '05'
    WHEN @MonthName = 'JUNE' THEN '06'
    WHEN @MonthName = 'JULY' THEN '07'
    WHEN @MonthName = 'AUGUST' THEN '08'
    WHEN @MonthName = 'SEPTEMBER' THEN '09'
    WHEN @MonthName = 'OCTOBER' THEN '10'
    WHEN @MonthName = 'NOVEMBER' THEN '11'
    WHEN @MonthName = 'DECEMBER' THEN '12'
    ELSE '' END)

    Let me know if you have any questions

    Regards,
    V.M. Damodharan
    "Your talent will be worthless, when you have fear and tension."


  • Sign In to post your comments