CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: T-SQL

  1. #1
    Join Date
    Jun 2001
    Posts
    1

    T-SQL

    I am trying to trim or truncate a Date within my SQL 7 database to get rid of the Timestamp associated with it. The current format is - mm/dd/yyyy hh:mm:ss
    I want it to look like - mm/dd/yyyy

    Any suggestions?


  2. #2
    Join Date
    Jan 2000
    Location
    Olen, Belgium
    Posts
    2,477

    Re: T-SQL

    If you mean in the database itself, that isn't possible, cause their is no difference between date and time, it's all datetime. If you really want to get rid of it, you can convert it to a string, but then you lose all the advantages of the date data type. Or you can do both, just create a computed column that holds the value as a string in a given format.
    If you just need to format it (like say for a report or query), there are several functions available. I think in this case you should use the convert function, which allows you to temporary convert it to a varchar with a given format (you should check out the SQL books online for more information on this function.)

    Tom Cannaerts
    [email protected]

    Programming today is a race between software engineers striving to build bigger and better idot-proof programs, and the universe trying to produce bigger and better idiots. So far, the universe is winning -- Rich Cook
    Tom Cannaerts
    email: [email protected]
    www.tom.be (dutch site)

  3. #3
    Join Date
    Dec 1999
    Location
    Dublin, Ireland
    Posts
    1,173

    Re: T-SQL

    The Convert keyword in SQL server/Sybase can be used e.g.


    Select Convert(VarChar(8),Timestamp,112) From TUSERS
    --Timestamp is of datatypoe DATETIME





    HTH,
    D.

    -------------------------------------------------
    Ex. Datis: Duncan Jones
    Merrion Computing Ltd
    http://www.merrioncomputing.com
    '--8<-----------------------------------------
    NEW -The printer usage monitoring application
    '--8<------------------------------------------

  4. #4
    Join Date
    May 2000
    Location
    New York, NY, USA
    Posts
    2,878

    Re: T-SQL

    If you are using this string in VB thenb you can format the string

    Format(MyDate,"mm/dd/yyyy")

    Iouri Boutchkine
    [email protected]
    Iouri Boutchkine
    [email protected]

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured