Concatenating dates

  • Hi All

    I have the following:

    Select Datepart(day,SNDF.DateTimeSampled) as LDay, Datepart(month,SNDF.DateTimeSampled) as LMonth, Datepart(Year,SNDF.DateTimeSampled) as LYear

    How can one concatenate all three to show in one column, please??!!

    Thank you in advance

    Anche 

  • Look up the CONVERT function. There are a number of different formats. eg:

    SELECT CONVERT(char(10), SNDF.DateTimeSampled, 103)

     

  • Hi All

    Thanks so much for all your input. I appreciate it. It's working fine now.

    THANK YOU

    Anche

     

     

  • If you only are trying to remove the TIME PART information, try this

     

    SELECT DATEADD(DAY, DATEDIFF(DAY, 0, YourDateTimeColumnHere), 0)

     

     


    N 56°04'39.16"
    E 12°55'05.25"

  • The answers of the SQL gurus are more clear and efficient, but note that you can always construct a composite column value by string concatenation:

    SELECT CAST(DATEPART(day,SNDF.DateTimeSampled) AS CHAR(2))

    + '/' + CAST(DATEPART(month,SNDF.DateTimeSampled) AS CHAR(2))

    + '/' + CAST(DATEPART(Year,SNDF.DateTimeSampled) AS CHAR(4))

    FROM WhatEverTable

Viewing 5 posts - 1 through 4 (of 4 total)

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