Results 1 to 3 of 3
  1. #1
    Join Date
    Jun 2004
    Posts
    14

    Unanswered: smalldatetime/Datepart

    Will someone please tell me how to pull the time out of a smalldatetime field.
    The code i am trying to use is as follows:

    Select datepart(hh:mm, TimeField1)
    from table1;

    This gives me an error. I have also tried datepart('hh:mm'... datepart("hh:mm"... and other variations but i cant get anything to work. Thanks in advance for any help!!

  2. #2
    Join Date
    Jul 2002
    Location
    Village, MD
    Posts
    621
    Try something like this:

    select cast(datepart(hh,getdate()) as varchar)+':'+
    case when datepart(mi,getdate())<10
    then '0'+cast(datepart(mi,getdate()) as varchar)
    else cast(datepart(mi,getdate()) as varchar)
    end

  3. #3
    Join Date
    Oct 2003
    Posts
    84
    CONVERT(VARCHAR, MyDateField, 8)

    will return a string representation of the time part in the "hh:mm:ss" format.

Posting Permissions

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