insert time into datetime field with SQL?

insert time into datetime field with SQL?

Post by aztecM » Fri, 28 Jul 2000 04:00:00



This is a newbie question, and hopefully an easy one to answer.

We are integrating a SQL Server 7 databse with Visual Interdev
for our intranet to track the time that our employees spend on
particular jobs. We currently have a field in a transaction
table that is used to store the time that an employee starts on
a particular job (the key to this table is the emp#, the job#
and the starttime). The field is set to datetime data type. If
you enter 8:30 in the time field through Visual Interdev, the
database stores only the time. When the emp types in 8:30, for
example, the database is updated with the default date (January
1, 1900) and the correct time. Here is the SQL statement used:

"UPDATE timesheet SET starttime ='" & Request.Form("starttime")
&  "'"

We only want the time stored in the field. Is this a problem
with the SQL statement? Are we missing a modifying parameter? We
can't find anything that relates to this specific problem
anywhere.

-----------------------------------------------------------

Got questions?  Get answers over the phone at Keen.com.
Up to 100 minutes free!
http://www.keen.com

 
 
 

insert time into datetime field with SQL?

Post by Harlan Messinge » Fri, 28 Jul 2000 04:00:00



>This is a newbie question, and hopefully an easy one to answer.

>We are integrating a SQL Server 7 databse with Visual Interdev
>for our intranet to track the time that our employees spend on
>particular jobs. We currently have a field in a transaction
>table that is used to store the time that an employee starts on
>a particular job (the key to this table is the emp#, the job#
>and the starttime). The field is set to datetime data type. If
>you enter 8:30 in the time field through Visual Interdev, the
>database stores only the time. When the emp types in 8:30, for
>example, the database is updated with the default date (January
>1, 1900) and the correct time. Here is the SQL statement used:

>"UPDATE timesheet SET starttime ='" & Request.Form("starttime")
>&  "'"

>We only want the time stored in the field. Is this a problem
>with the SQL statement? Are we missing a modifying parameter? We
>can't find anything that relates to this specific problem
>anywhere.

That's how just plain time is represented in a datetime field. January
1, 1900, is 0 for that data type. It's just like storing the value .45
in a float field, where it's essentially stored as 0.45, as opposed to
3.45 or 1152.45.

The important question is: how to use the contents of this field? For
display, the fact that there's a January 1, 1900, in there doesn't
matter. Use a formatting function to show only hours and minutes (and
seconds, if applicable). For time comparisons, use = or inequalities
in the usual manner. For time arithmetic, use dateadd or datediff as
necessary.

--
Harlan Messinger
There are no Zs in my actual e-mail address.