Results 1 to 3 of 3
  1. #1
    Join Date
    Jun 2003
    Posts
    20

    Question Unanswered: convert Datetime in a certain format

    Hi all. I want to print or convert a datatime value to a string in the following format 'dd/mm/yyyy hh:mm:ss AM|PM'. One example is '12/02/2007 9:44:50 AM'.

    I tried to use function convert(datatype[(length)], expression, style). But the problem is the available style in this function does not have the format I want. Is there any other ways to achieve it? Do I have to manually format the output string?

    Please help. Tons of thanks....

  2. #2
    Join Date
    Jun 2003
    Location
    Ohio
    Posts
    12,592
    Provided Answers: 1
    Why are you doing this in the database? Your front-end or reporting application should handle formatting.
    If it's not practically useful, then it's practically useless.

    blindman
    www.chess.com: "sqlblindman"
    www.LobsterShot.blogspot.com

  3. #3
    Join Date
    Jul 2003
    Location
    San Antonio, TX
    Posts
    3,662
    coolioo may need it in the extracted file, or something...
    Code:
    select
       convert(char(10), getdate(), 101) + ' ' +
       convert(varchar(45), getdate(), 108) +
       case when datepart(hour, getdate()) < 12 then 'AM' else 'PM' end
    "The data in a record depends on the Key to the record, the Whole Key, and
    nothing but the Key, so help me Codd."

Posting Permissions

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