Skip to Content
author's profile photo Former Member
Former Member

How do store a time type field in a database table?

We added a UDF of time type. SQL Server says its a small integer. After I pull the time off a date, I convert it to an integer. For example, I convert 6:00 AM to 600. When I try to store 600 in the field, I get a type mismatch exception. What am I doing wrong?

Add a comment
10|10000 characters needed characters exceeded

Related questions

3 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Nov 30, 2007 at 03:41 PM

    Hi,

    I really need an answer here. Has anyone had to update a user-defined field of the Time type using the DI API?

    Mike

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      Adele,

      Thanks a bunch!

      Your code was syntactically incorrect but it moved me in the right direction. Here is the code I ended up with:

      DateString = DateIn.ToString("yyyyMMdd HHmm")

      Time = Date.ParseExact(DateString, "yyyyMMdd HHmm", system.Globalization.DateTimeFormatInfo.InvariantInfo)

      Then update the Time field with the Time variable.

      This does the trick. It looks like it is only necessary to save a date data type in a time type field and only the time piece of it is saved.

      Thanks again,

      Mike

  • author's profile photo Former Member
    Former Member
    Posted on Nov 29, 2007 at 04:46 AM

    HI Mike

    U r trying to insert an integer value in the small int field so sql server is throning an expection , insted of small integer you should difine your field as date time data type.

    hope this helps u...............

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Nov 29, 2007 at 05:20 AM

    Hi Mike,

    While creating the field use the following code

    objUserFieldMD.TableName = TableName

    objUserFieldMD.Name = ColumnName

    objUserFieldMD.Description = ColDescription

    objUserFieldMD.Type = SAPbobsCOM.BoFieldTypes.db_Date

    objUserFieldMD.SubType = SAPbobsCOM.BoFldSubTypes.st_Time

    objUserFieldMD.add()

    Hope it helps you,if it helps please reward points

    Regards

    Vishnu

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.