to get only date or hour from getdate()

  • Hello, the getdate() returns date and hour of the system but I need to get only the date or the hour using getdate, How to? do I need to use datepart?

  • Either use datpart to get the pieces you need or look at CONVERT in BOL, for example

    CONVERT(VARCHAR,GETDATE(),101) returns mm/dd/yyy

    CONVERT(VARCHAR,GETDATE(),108) returns hh:mm:ss

    "Don't roll your eyes at me. I will tape them in place." (Teacher on Boston Public)

  • What about if I want to take a date and turn it into this format: mmddyy

    no slashes, hyphens etc.

    Thanks!!

  • use datepart and concatenate.

    datepart() + datepart() + datepart()

    Steve Jones

    steve@dkranch.net

  • Or

    select replace(convert(varchar(8),getdate(),1),'/','')

    You are limited using convert to the pre-defined list (see BOL), but removing the '/' gives you the format you require.

    Regards,

    Andy Jones

    andyj93@hotmail.com

    .

  • Thanks to both of you! I was hoping there was a format string command - but your suggestions will take care of it.

  • Hi

    select Replace(Convert(varchar(11),Getdate(),110),'-','')

    Shrinivas L.K.


    Shrinivas L.K.

Viewing 7 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic. Login to reply