Results 1 to 11 of 11
  1. #1
    Join Date
    Oct 2003
    Posts
    233

    Unanswered: How do you format an Getdate() to 11/30/2009

    How do you format an Getdate() to look like :11/30/2009

  2. #2
    Join Date
    Nov 2002
    Location
    Jersey
    Posts
    10,322
    Brett
    8-)

    It's a Great Day for America everybody!

    dbforums Yak CorralRadio 'Rita
    dbForums Member List
    I'm Good Once as I ever was

    The physical order of data in a database has no meaning.

  3. #3
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Code:
    SELECT GetDate()
         , Convert(char(12), GetDate(), 103)
         , ':' + Convert(char(12), GetDate(), 103)
    George
    Home | Blog

  4. #4
    Join Date
    Dec 2009
    Posts
    8
    The solution is the next :

    SELECT Day(Getdate()) + '/' + Month(Getdate()) + '/' + Year(Getdate())


    --
    Akarouche Mohamed

  5. #5
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Akarouche Mohamed, have you run your code? It will throw an error.
    George
    Home | Blog

  6. #6
    Join Date
    Nov 2002
    Location
    Jersey
    Posts
    10,322
    Quote Originally Posted by akarouche mohamed View Post
    The solution is the next :

    SELECT Day(Getdate()) + '/' + Month(Getdate()) + '/' + Year(Getdate())


    --
    Akarouche Mohamed

    ummmm....nooo

    -----------
    Msg 245, Level 16, State 1, Line 1
    Conversion failed when converting the varchar value '/' to data type int.
    It's a good idea to test before you post...and in any case, did you read about CONVERT????
    Brett
    8-)

    It's a Great Day for America everybody!

    dbforums Yak CorralRadio 'Rita
    dbForums Member List
    I'm Good Once as I ever was

    The physical order of data in a database has no meaning.

  7. #7
    Join Date
    Jan 2003
    Location
    Massachusetts
    Posts
    5,799
    Provided Answers: 11
    You format the date in the presentation layer. What language is your presentation layer written in?

  8. #8
    Join Date
    Dec 2009
    Posts
    8

    Convert

    Indeed,
    it will be better if you modify the previous code to the next :

    SELECT Convert(varchar(2), Day(Getdate())) + '/' + Convert(varchar(2), Month(Getdate())) + '/' + Convert(varchar(4), Year(Getdate()))

    ----
    akarouche mohamed

  9. #9
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    Sure, if you like using 12 functions when you could use 2.

    And I agree with MCrowley. Here's a good reason why:
    How to format a Date or DateTime in SQL Server
    Testimonial:
    pootle flump
    ur codings are working excelent.

  10. #10
    Join Date
    Jul 2003
    Location
    The Dark Planet
    Posts
    1,401
    SelectCONVERT(varchar(10),getdate(),101)
    Get yourself a copy of the The Holy Book

    order has no physical Brett in The meaning of a Kaiser . -database data

  11. #11
    Join Date
    Feb 2010
    Posts
    1
    select CONVERT(varchar(20),getdate(),101) converteddate,GETDATE() actualdate;

Posting Permissions

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