How to Show time in my table?

  • Hi Friends,

    My Table strct:

    ===========

    create table show_bus

    (

    id int identity,

    from_p varchar(100),

    to_p varchar(100),

    timin time

    )

    My Expecting OUTPUT:

    ================

    insert into show_bus values('a','b','6:05 AM')

    when i tried to enter these format its showing error on sql server 2000

    kindly help to me

  • You've posted this in the SQL 2008 forum but you're referring to SQl 2000 - which is it?

    Time was only intoduced in the 2008 version, it is not valid in 2000.

  • you need to Convert/Cast this value in Time to be inserted properly.

    whether its 2000 or 2008.

  • The code works fine for me using SQL Server 2008 R2 although casting it beforehand is still a good idea.

    Mark

  • Here's how you can get it back out as AM/PM:

    select CONVERT(varchar(15),CAST(timin AS TIME),100) as convtimein, * from show_bus

    Mark

  • raghuldrag (12/5/2013)


    Hi Friends,

    My Table strct:

    ===========

    create table show_bus

    (

    id int identity,

    from_p varchar(100),

    to_p varchar(100),

    timin time

    )

    My Expecting OUTPUT:

    ================

    insert into show_bus values('a','b','6:05 AM')

    when i tried to enter these format its showing error on sql server 2000

    kindly help to me

    You need to pay attention to what the error is saying. 😉 The TIME datatype isn't available in SQL Server 2000. Store the time in a DATETIME datatype and format it when you select from it.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

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

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