Results 1 to 10 of 10
  1. #1
    Join Date
    May 2004
    Posts
    14

    Unanswered: using convert function for date in transact sql

    Dear all,

    Is there any one know how to use CONVERT function in TSQL to convert the datetime field into the following format.

    YYYY/MM/DD HH24:MIS

    Regards,

    Thomas HO

  2. #2
    Join Date
    Feb 2004
    Location
    Poland
    Posts
    96
    select CONVERT(CHAR(24),GETDATE(),120)

  3. #3
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    Depending on how picky you are, you might prefer:
    Code:
    SELECT Replace(Convert(CHAR(19), GetDate(), 120), '-', '/')
    -PatP

  4. #4
    Join Date
    May 2004
    Posts
    14
    Sorry, but I get the following error message:-

    Line 4:
    120 is not a valid style number when converting from DATETIME to a character string.

  5. #5
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    ????? what version of sql server?

    i use 120 all the time, it's my favourite, it's the ISO standard
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  6. #6
    Join Date
    May 2004
    Posts
    14
    Hi Ruby,

    I'm using Sybase 12.5.1.

    Regards,

    Thomas HO

  7. #7
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    sorry, i keep forgetting that there are actually two completely different databases, both coincidentally called sql server

    you're right, sybase's does not apeear to supoprt style 120

    see http://manuals.sybase.com/onlinebook...uery=convert#X

    note that only two styles include the time
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  8. #8
    Join Date
    May 2004
    Posts
    14
    Ruby,

    Do you mean I have no way to convert a datetime into the following format:-

    YYYY/MM/DD HH24:MIS

  9. #9
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    please, the name is Rudy -- "Ruby" once is a typo, twice is an error

    yes, you can get the format you want, but it may take several functions

    do you have a manual?
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  10. #10
    Join Date
    May 2004
    Posts
    14

    Talking

    Thanks Rudy!

    I manage to do it with the following:-

    SELECT Convert(CHAR(10), GetDate(), 111)+' '+Convert(CHAR(8),GetDate(),108)


    Thanks a lot !!!!

    Bye!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •