Format date into a common format having two types of values in it.

  • I have a table and it has a column of nVarchar(max) data type. It has values in it as shown below. These values are keyed in from Angular UI.

    12-18-2019 T 09:00 AM

    12-18-2019

    12-15-2019

    Now I want to retrieve the values in one single format as MMM dd yyyy HH:mm AM (eg: Dec 18 2019 09:00AM). Output should be like below.

    Dec 18 2019 09:00 AM

    Dec 18 2019 00:00 AM

    How can I do this ?

    Sanz
  • like this?

    -- create some consumable data... 
    CREATE TABLE test(
     txtdatetime varchar(50)
     );
    GO
    INSERT INTO test(txtdatetime) values ('12-18-2019 T 09:00 AM')
    ,('12-18-2019')
    ,('12-15-2019');


    SELECT txtDateTime As origvalue
     , CAST(REPLACE(txtDateTime,' T','') AS DateTime) AS testreturn
    FROM test;

     

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply