date format yyyyMMddhhmmss

  • how to display date in yyyyMMddhhmmss format

  • Hi

    What do you mean with display?

    If you want to select DATETIME values in specified format:

    It is possible, but you should not do it. You should format your output format within the client.

    If you want to format your output within the client:

    Which programming language? Which data access library?

    Greets

    Flo

  • use convert function and you can do this. look for Convert options in SQL BOL , hope this helps 🙂

  • Use CONVERT with the correct style (probably 121 would do) and length, and then REPLACE delimiters if you don't want them in the result.

  • HI,

    Try this..

    SELECT CONVERT(VARCHAR(19), GETDATE(), 120) DATE

    ,REPLACE(REPLACE(REPLACE(CAST(CONVERT(VARCHAR(19), GETDATE(), 120) AS VARCHAR(20)),'-',''),':',''),' ','') FORMATDATE

    Regards,

    Ashok S

  • here's how i do it:

    FormattedDate SQL

    20090320-09:33:49:700 SELECT CONVERT(VARCHAR,@date,112) + '-' + CONVERT(VARCHAR,@date,114)

    20090320-093349700 SELECT CONVERT(VARCHAR,@date,112) + '-' + REPLACE(CONVERT(VARCHAR,@date,114),':','')

    20090320093349 SELECT CONVERT(VARCHAR,@date,112) + LEFT(REPLACE(CONVERT(VARCHAR,@date,114),':',''),6)

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

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

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