SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Zealot
    Join Date
    Mar 2011
    Posts
    173
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Help on sql datetime format

    Hello any one...

    can anyone direct me how to create a dateformat in SQL..

    mm-dd-yy hh:mm:ss: am or pm
    example:
    03-05-2011 03:56:25 pm

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,273
    Mentioned
    60 Post(s)
    Tagged
    3 Thread(s)
    i don't understand the question

    all sql databases have built-in date formats

    which database are you using? microsoft sql server?
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    SitePoint Zealot
    Join Date
    Mar 2011
    Posts
    173
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    what i mean is to convert the datetime format..

    mm-dd-yy hh:mm:ss: am or pm
    example:
    03-05-2011 03:56:25 pm

  4. #4
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,273
    Mentioned
    60 Post(s)
    Tagged
    3 Thread(s)
    CONVERT(CHAR(10),mydatetime,110) gives mm-dd-yyyy

    CONVERT(CHAR(8),mydatetime,108) gives hh:mm:ss (24-hour)

    other styles are available which include the AM/PM variation

    you may have to mix & match and use additional SUBSTRING and concatenation functions to get the exact format you want

    check the documentation for the CONVERT function
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"


Bookmarks

Posting Permissions

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