Groups | Blog | Home
all groups > vb.net > september 2004 >

vb.net : DateTime Problem


Bryan
9/6/2004 8:31:02 PM
I have a sql field called OrderTime.. smalldatetime in SQL 2000 length 4

I have the following in my code:

ffSql.OrderTime = Now.ToString("hh:mm:ss tt")

When I try to insert this into my table. If I replace the top with

ffSql.OrderTime = Today
instead of
ffSql.OrderTime = Now.ToString("hh:mm:ss tt")

What I want is to place the time into the field not the date and time.

Can someone help?
Cor Ligthert
9/7/2004 8:23:10 AM
Bryan,

Especially for globalization it is better not to use your kind of code,

In my opinion is better to use something as
Dim mydate As DateTime = New Date(1900, 1, 1, Now.Hour, Now.Minute,
Now.Second)

(As far as I know has the datatable no "smalldatetime" only "datetime",
however when I wrong in that let somebody correct me?).

I hope this helps,

Cor


"Bryan"

[quoted text, click to view]

Greg Burns
9/7/2004 8:43:47 AM
Another choice, if storing a date bothers you, is to store time as an
integer. For example, numbers of seconds past midnight.

Dim d As DateTime = Now
Dim ts As TimeSpan = d.TimeOfDay
Dim NumOfSecs As Integer = ts.TotalSeconds

Greg

[quoted text, click to view]

AddThis Social Bookmark Button