Date Format

  • Hi Team,

    Am using below code to display name and "Date of birth"

    but Field DOB is not coming in Date format.

    select @FinalString=(SELECT RTRIM(+ISNULL('Name ','')+' : ' +ISNULL(+CAST(NAME AS VARCHAR(100))+' ','') +ISNULL(' DOB :'+CAST(DOB AS VARCHAR(100))+' ',''))

    FROM ETCOL i want date format in below format.

    rtrim(convert(varchar, DOB,107)) + ')'

    Can u please help me .....

  • Can you provide some sample data of the format that the DOB is and how it should be formatted

  • Date format in DOB Column is : '2012-09-30 00:00:00.000'

    i want date format in : Sep 30, 2012

  • Well that converts perfectly.

    Can you provide the DDL and sample data for table ETCOL along with your full query?

  • BEGIN

    select @FinalString =(SELECT RTRIM(+ISNULL('Name','')+' : ' +ISNULL(+CAST(Name AS VARCHAR(100))+' ',''))

    FROM ETCOL WHERE RIGHT_TEXT ='Name') +CHAR(10)

    END

    ELSE

    BEGIN

    select @FinalString=(SELECT RTRIM(+ISNULL('Name','')+' : ' +ISNULL(+CAST(Name AS VARCHAR(100))+' ','') +ISNULL(' DOB :'+CAST(DOB AS VARCHAR(100))+' ',''))

    FROM ETCOL WHERE RIGHT_TEXT ='Name') +CHAR(10)

    END

    ----------

    If the DOB is not null, then i want the date format like : Sep 30, 2012

  • Please post the create table definition along with data for the table so what we can build up the string for you.

  • CREATE TABLE ETCOL (NAME VARCHAR (50), DOB DATETIME)

  • And now some data?

  • Hi Team,

    Table and data is normat,

    in my query am checking whether it is null or not null and

    am not converting to normal date format.

    can u please convert it to normal date if it is not null.

    Please help me.....

  • Minnu (12/5/2012)


    Hi Team,

    Am using below code to display name and "Date of birth"

    but Field DOB is not coming in Date format.

    select @FinalString=(SELECT RTRIM(+ISNULL('Name ','')+' : ' +ISNULL(+CAST(NAME AS VARCHAR(100))+' ','') +ISNULL(' DOB :'+CAST(DOB AS VARCHAR(100))+' ',''))

    FROM ETCOL i want date format in below format.

    rtrim(convert(varchar, DOB,107)) + ')'

    Can u please help me .....

    If you want it formated like rtrim(convert(varchar, DOB,107)) then use it in the select statement?

    select @FinalString=(SELECT RTRIM(+ISNULL('Name ','')+' : ' +

    ISNULL(+CAST(NAME AS VARCHAR(100))+' ','') +

    ISNULL(' DOB :'+rtrim(convert(varchar(10), DOB,107)) +' ','')) FROM ETCOL

    I prefer to be explicit with my CONVERT(VARCHAR(12), DOB,107), since you are going to get a 30 character varchar variable by default, instead of the 12 character that you need.

  • We ask for table and data so that we can write a T-SQL statement and test it to ensure that what we do is what your require.

    For reference please read the link in my signature on posting code and data for the best help.

Viewing 11 posts - 1 through 10 (of 10 total)

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