Click here to Skip to main content
15,912,021 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi guys and thanks to those folks who have answered my questions before, you are a great help :)

Anyway here's my Q for today:

So I have a database table with a time(7) field and I am using visual basic 2010 express to interface with the DB.

when I use this code :
VB
Time_StampTextBox.Text = Date.Now.TimeOfDay.ToString


I get this result
HTML
08:18:01.8205871
, the trailing 7 digits are not wanted

I tried using this code:

VB
Dim Arg1 = Date.Now.ToShortTimeString
        Time_StampTextBox.Text = Arg1


and I get 8:18 AM which is perfect, but the DB.table wont accept it into the table
and I dont get an error message, ??

also tried this
VB
Format(Arg1, "h:m:s")
but all i got was "h:m:s"

is it to do with the number 7 in the field definition ??, or somthing else?

thanks guys :)
Posted
Updated 15-Sep-12 10:49am
v3
Comments
[no name] 15-Sep-12 16:35pm    
And so? What is your question?

1 solution

You should consider storing the date in a separate variable:
VB
Dim ToDay as new DateTime
ToDay = DateTime.Now
textBox1.Text = ToDay.ToString("HH:mm:ss")


See microsoft documentation:
http://msdn.microsoft.com/en-us/library/system.datetime.today.aspx[^]
http://msdn.microsoft.com/en-us/library/zdtaw1bw.aspx[^]

And to store the date you simply use ToDay. If you want to change the time you should consider using a DateTime picker:
http://msdn.microsoft.com/en-us/library/ms229631.aspx[^]
 
Share this answer
 
v2
Comments
It is what it is 16-Sep-12 0:06am    
Perfect ---thanks a lot :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900