Insert Time into SmallDateTime Column?

Discussion in 'ASP General' started by James Goodman, Jan 21, 2004.

  1. I have an asp page which the user enters a time(e.g. 12:21). I need to
    insert this time into a SQL Server DB, which has a smalldatetime column.

    I have tried everything I can think of (such as CDate, TimeValue,
    FormatDateTime etc) to convert the time string, into a valid time. However,
    the insert always try to insert a datetime datatype (e.g. 12/12/1899
    12:21:00).

    I am trying to process the insert through ado, eg:

    objRS.AddNew
    objRS("Field1") = strText
    objRS("DateField") = dteValue
    objRS.Update

    Any suggestions as to how I can solve this?

    --
    Cheers,


    James Goodman MCSE, MCDBA
    http://www.angelfire.com/sports/f1pictures
    James Goodman, Jan 21, 2004
    #1
    1. Advertising

  2. SQL Server will always add a date component. If the date is always
    12/12/1899, can't you just ignore the date part???
    http://www.aspfaq.com/2206

    (Also, SQL Server would put 1900-01-01 as the date, so I think that's
    VBScript adding the date for you. And finally, use an INSERT statement
    instead of rs.AddNew.)

    --
    Aaron Bertrand
    SQL Server MVP
    http://www.aspfaq.com/




    "James Goodman" <j a m e .u k> wrote in message
    news:bultgq$q02$...
    > I have an asp page which the user enters a time(e.g. 12:21). I need to
    > insert this time into a SQL Server DB, which has a smalldatetime column.
    >
    > I have tried everything I can think of (such as CDate, TimeValue,
    > FormatDateTime etc) to convert the time string, into a valid time.

    However,
    > the insert always try to insert a datetime datatype (e.g. 12/12/1899
    > 12:21:00).
    >
    > I am trying to process the insert through ado, eg:
    >
    > objRS.AddNew
    > objRS("Field1") = strText
    > objRS("DateField") = dteValue
    > objRS.Update
    >
    > Any suggestions as to how I can solve this?
    >
    > --
    > Cheers,
    >
    >
    > James Goodman MCSE, MCDBA
    > http://www.angelfire.com/sports/f1pictures
    >
    >
    Aaron Bertrand [MVP], Jan 21, 2004
    #2
    1. Advertising

  3. My problem is not that I cant ignore the date part of the time inserted.

    I simply cannot insert anything into a smalldatetime field from asp.

    Can you give me, or point me in the direction of an example for using an
    insert command instead of objRS.AddNew etc?



    --
    Cheers,


    James Goodman MCSE, MCDBA
    http://www.angelfire.com/sports/f1pictures
    James Goodman, Jan 21, 2004
    #3
  4. sql = "INSERT table_name(smalldatetime_column_name) VALUES('20040121
    09:35')"
    connObject.execute sql,,129

    --
    Aaron Bertrand
    SQL Server MVP
    http://www.aspfaq.com/




    "James Goodman" <j a m e .u k> wrote in message
    news:bum1au$8ug$...
    > My problem is not that I cant ignore the date part of the time inserted.
    >
    > I simply cannot insert anything into a smalldatetime field from asp.
    >
    > Can you give me, or point me in the direction of an example for using an
    > insert command instead of objRS.AddNew etc?
    >
    >
    >
    > --
    > Cheers,
    >
    >
    > James Goodman MCSE, MCDBA
    > http://www.angelfire.com/sports/f1pictures
    >
    >
    Aaron Bertrand - MVP, Jan 21, 2004
    #4
  5. James Goodman, Jan 21, 2004
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Salim Afþar
    Replies:
    1
    Views:
    1,669
  2. Fred Nelson

    SmallDateTime and NULL Values

    Fred Nelson, Mar 2, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    543
    Natty Gur
    Mar 2, 2004
  3. Pat

    smalldatetime problem

    Pat, Aug 31, 2005, in forum: ASP .Net
    Replies:
    3
    Views:
    3,967
    =?Utf-8?B?TWlsb3N6IFNrYWxlY2tp?=
    Sep 2, 2005
  4. =?Utf-8?B?Um9iZXJ0IFdpbGxoaXRl?=

    smalldatetime Null in SQL for ASP.net Page

    =?Utf-8?B?Um9iZXJ0IFdpbGxoaXRl?=, Oct 6, 2005, in forum: ASP .Net
    Replies:
    3
    Views:
    2,907
    Patirck Ige
    Oct 6, 2005
  5. .Net Sports

    Changing smalldatetime to string

    .Net Sports, Nov 18, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    3,670
    .Net Sports
    Nov 18, 2005
Loading...

Share This Page