Results 1 to 15 of 15
  1. #1
    Join Date
    Apr 2003
    Posts
    176

    Unanswered: date part of date time

    SELECT ltrim(str(datepart(yyyy,getdate()))) +'-'+
    replicate('0',2-len(ltrim(str(datepart(mm,getdate())))))+ltrim(str (datepart(mm,getdate())))+'-' +replicate('0',2-len(ltrim(str(datepart(dd,getdate())))))
    +ltrim(str(datepart(dd,getdate())))

    This is how i am getting datepart of datetime.Is there any other way to get the date and also time seperately..

    Thanks.

  2. #2
    Join Date
    Jun 2003
    Location
    Ohio
    Posts
    12,592
    Provided Answers: 1
    Convert(char(10), getdate(), 120)
    If it's not practically useful, then it's practically useless.

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

  3. #3
    Join Date
    Nov 2002
    Location
    Jersey
    Posts
    10,322
    Code:
    SELECT CONVERT(varchar(10),GetDate(),101), CONVERT(varchar(10),GetDate(),108)
    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.

  4. #4
    Join Date
    Jun 2003
    Location
    Ohio
    Posts
    12,592
    Provided Answers: 1
    Beat you by one second, Kaiser! Nyah nyah nyah! Too slow! Ya snooze, ya looze!
    If it's not practically useful, then it's practically useless.

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

  5. #5
    Join Date
    Apr 2003
    Posts
    176
    SELECT CONVERT(varchar(10),GetDate(),101), CONVERT(varchar(10),GetDate(),108)

    Where should i know to use 101 and 108 in convert functions.I could get that from BOl....
    Can u help me with that.

    Thanks and sorry for asking such a silly question.

  6. #6
    Join Date
    Apr 2003
    Posts
    176
    I'm sorry i got that myself.

    Thank u all.

  7. #7
    Join Date
    Jul 2002
    Location
    Village, MD
    Posts
    621

    Thumbs up

    Quote Originally Posted by bruce_Reid
    I'm sorry i got that myself.

    Thank u all.
    Congratulations! Because of forum a lot of people became so lazy but not you.

  8. #8
    Join Date
    Nov 2002
    Location
    Jersey
    Posts
    10,322
    Quote Originally Posted by blindman
    Beat you by one second, Kaiser! Nyah nyah nyah! Too slow! Ya snooze, ya looze!

    Yeah...see what happens when work gets in the way...

    I'm giving out specs over the phone to a noob while I'm doing this...

    And this ain't sqlteam...that's 1 minute increments

    Damn...[sniped] anyway

    And what's with 120?

    bleeeeeach....

    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.

  9. #9
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    Quote Originally Posted by Brett Kaiser
    And what's with 120?
    Wah, wah, waaaaah!

    120 is just the "junior grade" version of 121, my preferred style!

    -PatP

  10. #10
    Join Date
    Jun 2003
    Location
    Ohio
    Posts
    12,592
    Provided Answers: 1
    121? How pretentious. 120 shines in its simplicity and elegance.

    Dude, 121 is SOOOOO last version......

    And what's with the varchar, eh?
    If it's not practically useful, then it's practically useless.

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

  11. #11
    Join Date
    Nov 2002
    Location
    Jersey
    Posts
    10,322
    Personally I like 126..talk about pretentions...but that's just my mainframe db2 talking...

    too bad they lost pos 4-6 of their milliseconds...gotta be the cpu's fault..right?

    Figured he wanted 101 though..nice and pretty...

    And geez....I need to speak with Karolyn or ms_sql_dba to straighten you out?



    I saw you suck'n up blind dude...

    Varchar...force of habit....

    we need more banter in the corral....

    http://www.dbforums.com/showthread.p...44#post3672844
    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.

  12. #12
    Join Date
    Jun 2003
    Location
    Ohio
    Posts
    12,592
    Provided Answers: 1
    Don't threaten to sick your dogs on me!

    Like I'm gonna be scared of a "126"er...
    If it's not practically useful, then it's practically useless.

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

  13. #13
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    Quote Originally Posted by blindman
    Dude, 121 is SOOOOO last version......
    Oh, they used to say that about my Leisure Suit and silver tipped cowboy boots too!

    -PatP

  14. #14
    Join Date
    Jun 2003
    Location
    Ohio
    Posts
    12,592
    Provided Answers: 1
    Hold on to those. They're coming back.
    If it's not practically useful, then it's practically useless.

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

  15. #15
    Join Date
    Nov 2002
    Location
    Jersey
    Posts
    10,322
    Quote Originally Posted by blindman
    Hold on to those. They're coming back.

    I hated the 70's..

    What do you guys think about this:

    http://www.dbforums.com/t996699.html
    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.

Posting Permissions

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